From: Peep P. <so...@us...> - 2004-03-18 20:56:01
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1603 Modified Files: lex.l Log Message: Added character constants. Index: lex.l =================================================================== RCS file: /cvsroot/agd/server/src/lex.l,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- lex.l 12 Mar 2004 08:40:10 -0000 1.5 +++ lex.l 18 Mar 2004 20:46:20 -0000 1.6 @@ -6,6 +6,7 @@ The comment should span two lines. */ %x in_string in_string_backslash +%x charconst charconstgotten charbackslash %x comment linecomment %option yylineno %{ @@ -28,7 +29,8 @@ futurepos, #endif warned_newlines, - ignore_white_space; + ignore_white_space, + warned_charconst; #ifdef DEBUG #define RET(type, value, tok) \ @@ -136,6 +138,85 @@ } } + /* character constants */ +' BEGIN(charconst); +<charconst>{ + ' BEGIN(INITIAL); + \\ { + BEGIN(charbackslash); + } + . { + yylval.i = *yytext; + BEGIN(charconstgotten); + RET(d, yylval.i, L_INTEGER); + } + +} + +<charconstgotten>{ + ' { + warned_charconst = 0; + BEGIN(INITIAL); + } + . { + printf("anything\n"); + warned_charconst = 1; + comp_error("multi-character character constant"); + } +} + +<charbackslash>{ + ' { + yylval.i = '\''; + RET(c, '\'', L_INTEGER); + BEGIN(charconstgotten); + } + n { + yylval.i = '\n'; + BEGIN(charconstgotten); + RET(d, yylval.i, L_INTEGER); + } + r { + yylval.i = '\r'; + BEGIN(charconstgotten); + RET(c, '\r', L_INTEGER); + } + t { + yylval.i = '\t'; + BEGIN(charconstgotten); + RET(c, '\t', L_INTEGER); + } + a { + yylval.i = '\a'; + BEGIN(charconstgotten); + RET(c, '\a', L_INTEGER); + } + b { + yylval.i = '\b'; + BEGIN(charconstgotten); + RET(c, '\b', L_INTEGER); + } + f { + yylval.i = '\f'; + BEGIN(charconstgotten); + RET(c, '\f', L_INTEGER); + } + e { + yylval.i = '\27'; + BEGIN(charconstgotten); + RET(c, '\27', L_INTEGER); + } + \\ { + yylval.i = '\\'; + BEGIN(charconstgotten); + RET(c, '\\', L_INTEGER); + } + . { + comp_error("invalid escape code"); + BEGIN(INITIAL); + } +} + /* operators */ ">" RET(s, ">", L_GT); ">=" RET(s, ">=", L_GE); |