%{ #define YYSTYPE SLTNode * #define YY_USER_ACTION yyadvancelocation(yylloc, yyleng, yytext); #include #include #include "sun_parser.h" #include #include static void yyadvancelocation(YYLTYPE *location, long length, const char *text); #define YY_INPUT(buf, result, max_size) result = yyextra->readCallback(buf, max_size, yyextra->readCallbackParameter); //#define YY_DECL int yylex(YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner, SunSourceReadCallback readCallback) %} %option bison-bridge %option bison-locations %option never-interactive %option noyywrap %option nounput %option noinput %option reentrant %option extra-type="SLCLexerExtra *" %x SL_COMMENT %x ML_COMMENT %% "//" { BEGIN(SL_COMMENT); } \n { BEGIN(INITIAL); } . ; /* Eat comments */ "/*" { BEGIN(ML_COMMENT); } "*/" { BEGIN(INITIAL); } \n ; /* Eat comments */ . ; /* Eat comments */ [ \t\n] ; /* Eat whitespace */ "if" { return IF; } "else" { return ELSE; } "for" { return FOR; } "do" { return DO; } "while" { return WHILE; } "break" { return BREAK; } "struct" { return TYPE; } "return" { return RETURN; } "sleep" { return SLEEP; } "false" { *yylval = sltNodeMakeBoolean(false); return BOOL_FALSE; } "true" { *yylval = sltNodeMakeBoolean(true); return BOOL_TRUE; } "+=" { return ADD_ASSIGN; } "-=" { return SUBTRACT_ASSIGN; } "*=" { return MULTIPLY_ASSIGN; } "/=" { return DIVIDE_ASSIGN; } "%=" { return MOD_ASSIGN; } "&&" { return LOGICAL_AND; } "||" { return LOGICAL_OR; } "==" { return EQUAL; } "!=" { return NOT_EQUAL; } "<=" { return LT_EQUAL; } ">=" { return GT_EQUAL; } /*"++" { return INCREMENT; } "--" { return DECREMENT; }*/ [0-9]+\.[0-9]+ { *yylval = sltNodeMakeFloat(atof(yytext)); return FLOAT; } [0-9]+ { *yylval = sltNodeMakeInteger(atoi(yytext)); return INT; } i[0-9]+ { *yylval = sltNodeMakeRawInteger(atoi(&yytext[1])); return INT; } @\"[^\"\n]*\" { *yylval = sltNodeMakeKey(yytext); return STRING; } \"[^\"\n]*\" { *yylval = sltNodeMakeString(yytext); return STRING; } [a-zA-Z0-9_]+ { *yylval = sltNodeMakeIdentifier(yytext); return IDENTIFIER; } . { return yytext[0]; } %% static void yyadvancelocation(YYLTYPE *location, long length, const char *text) { location->first_column = location->last_column; location->first_line = location->last_line; for (long i = 0; i < length; ++i) { if (text[i] == '\n') { ++location->last_line; location->last_column = 0; } else { ++location->last_column; } } }