From: Peep P. <so...@us...> - 2004-06-07 15:42:47
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8440 Modified Files: lex.l Log Message: Support for multi-line C++ style comments; rearranged headers; added __VERSION__ and __ARCH__ Index: lex.l =================================================================== RCS file: /cvsroot/agd/server/src/lex.l,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- lex.l 3 Apr 2004 20:18:39 -0000 1.14 +++ lex.l 7 Jun 2004 15:42:38 -0000 1.15 @@ -1,19 +1,17 @@ -/* TODO: - // shouldn't end after an unmatched \ - i.e. - // foo \ - foo - The comment should span two lines. -*/ %x in_string in_string_backslash %x charconst charconstgotten charbackslash %x comment linecomment %{ +#include "config.h" #include "compile_options.h" -#include "lpc_incl.h" +#include "list.h" +#include "lpc.h" +#include "object.h" #include "compile.h" #include "lang.h" #include "sys.h" /* conf_t */ +#include "arch.h" + #define pos yylloc.first_column #define line yylloc.first_line @@ -48,37 +46,35 @@ char *string_buf_ptr; %% /* comments */ -"/*" pos += 2; BEGIN(comment); -"*/" { - comp_error("unmatched */"); - pos += 2; - BEGIN(INITIAL); +"/*" pos += 2; BEGIN(comment); +"*/" { + comp_error("unmatched */"); + pos += 2; + BEGIN(INITIAL); } <comment>{ "*/" pos += 2; BEGIN(INITIAL); - . pos++; - \n NEWLINE(); + . pos++; + \n NEWLINE(); } + "//" pos += 2; BEGIN(linecomment); <linecomment>{ - . pos++; - \n NEWLINE(); BEGIN(INITIAL); + \\\n NEWLINE(); + . pos++; + \n NEWLINE(); BEGIN(INITIAL); } /* strings */ -\" { - string_buf_ptr = string_buf; - pos++; - BEGIN(in_string); - } +"\"" string_buf_ptr = string_buf; pos++; BEGIN(in_string); <in_string>{ \\ pos++; BEGIN(in_string_backslash); - \" { - *string_buf_ptr = '\0'; - yylval.str = stringdup(string_buf); - BEGIN(INITIAL); - RET(s, string_buf, L_STRING); - } + \" { + *string_buf_ptr = '\0'; + yylval.str = stringdup(string_buf); + BEGIN(INITIAL); + RET(s, string_buf, L_STRING); + } [ ] STRING_PUTWHITESPACE(1); \t STRING_PUTWHITESPACE(8); . { @@ -90,15 +86,16 @@ } \n comp_error("multi-line string"); } + <in_string_backslash>{ - [nr] STRING_PUTCHAR2('\r', '\n'); - t STRING_PUTCHAR('\t'); - a STRING_PUTCHAR('\a'); - b STRING_PUTCHAR('\b'); - f STRING_PUTCHAR('\f'); - e STRING_PUTCHAR('\27'); - \" STRING_PUTCHAR('"'); - \\ STRING_PUTCHAR('\\'); + [nr] STRING_PUTCHAR2('\r', '\n'); + t STRING_PUTCHAR('\t'); + a STRING_PUTCHAR('\a'); + b STRING_PUTCHAR('\b'); + f STRING_PUTCHAR('\f'); + e STRING_PUTCHAR('\33'); + \" STRING_PUTCHAR('"'); + \\ STRING_PUTCHAR('\\'); \n { NEWLINE(); ignore_white_space = 1; @@ -122,8 +119,7 @@ yylval.i = *yytext; BEGIN(charconstgotten); RET(d, yylval.i, L_INTEGER); - } - + } } <charconstgotten>{ @@ -188,36 +184,35 @@ BEGIN(INITIAL); } } - + + /* fake preprocessor macros */ +"__VERSION__" { + yylval.str = PACKAGE_VERSION; + RET(s, "__VERSION__", L_STRING); + } +"__ARCH__" { + yylval.str = PLATFORM; + RET(s, "__ARCH__", L_STRING); + } + /* operators */ -">" RET(s, ">", L_GT); ">=" RET(s, ">=", L_GE); -"<" RET(s, "<", L_LT); "<=" RET(s, "<=", L_LE); "||" RET(s, "||", L_OR); "&&" RET(s, "&&", L_AND); -"-" RET(s, "-", L_MINUS); -"->" RET(s, "->", L_DEREF); +"->" RET(s, "->", L_ARROW); "--" RET(s, "--", L_DEC); -"!" RET(c, '!', L_NOT); "!=" RET(s, "!=", L_NE); -")" RET(c, ')', ')'); "==" RET(s, "==", L_EQ); -"=" RET(c, '=', L_ASSIGN); "++" RET(s, "++", L_INC); -"+" RET(c, '+', L_PLUS); "**" RET(s, "**", L_POW); -"**=" RET(s, "**=", L_POWE); -"*" RET(c, '*', L_MUL); -"/" RET(c, '/', L_DIV); -"%" RET(c, '%', L_MOD); -"+=" RET(s, "+=", L_PE); -"-=" RET(s, "-=", L_ME); -"*=" RET(s, "*=", L_MUE); -"/=" RET(s, "/=", L_DE); -"%=" RET(s, "%=", L_MOE); +"**=" RET(s, "**=", L_POW_EQ); +"+=" RET(s, "+=", L_PLUS_EQ); +"-=" RET(s, "-=", L_MINUS_EQ); +"*=" RET(s, "*=", L_MUL_EQ); +"/=" RET(s, "/=", L_DIV_EQ); +"%=" RET(s, "%=", L_MOD_EQ); ".." RET(s, "..", L_RANGE); -":" RET(s, ":", L_RANGE); "({" RET(s, "({", L_OPEN_ARRAY); "([" RET(s, "([", L_OPEN_MAPPING); @@ -233,16 +228,16 @@ [0-9]+ yylval.i = atoi(yytext); RET(d, yylval.i, L_INTEGER); return RET(s, "return", L_RETURN); -if RET(s, "if", L_IF); +if RET(s, "if", L_IF); else RET(s, "else", L_ELSE); -do RET(s, "do", L_DO); +do RET(s, "do", L_DO); while RET(s, "while", L_WHILE); break RET(s, "break", L_BREAK); continue RET(s, "continue", L_CONTINUE); -for RET(s, "for", L_FOR); +for RET(s, "for", L_FOR); void yylval.i = T_VOID; RET(s, "void", L_DATA_TYPE); -int yylval.i = T_INT; RET(s, "int", L_DATA_TYPE); +int yylval.i = T_INT; RET(s, "int", L_DATA_TYPE); string yylval.i = T_STRING; RET(s, "string", L_DATA_TYPE); mixed yylval.i = T_MIXED; RET(s, "mixed", L_DATA_TYPE); object yylval.i = T_OBJECT; RET(s, "object", L_DATA_TYPE); |