%{ #include #include #include "parser.tab.h" //#define YY_DECL int yylex( YYSTYPE *yylval, struct YYLTYPE *llocp, yyscan_t yyscanner ) //YY_DECL; # define YY_USER_ACTION yylloc->last_column += yyleng; %} %option reentrant noyywrap nounput batch %option bison-bridge bison-locations %x sitname %x comment %x dqstr sqstr tdqstr tsqstr %% "<=" { return tokLtEq; } ">=" { return tokGtEq; } "==" { return tokCmp; } "+=" { return tokPlusAssign; } "-=" { return tokMinusAssign; } "*=" { return tokTimesAssign; } "/=" { return tokDivideAssign; } [-{}<>=+/*,();:.[\]] { return yytext[0]; } game { return tokGame; } global { return tokGlobal; } function { return tokFunction; } situation { return tokSituation; } player { return tokPlayer; } while { return tokWhile; } for { return tokFor; } each { return tokEach; } do { return tokDo; } in { return tokIn; } if { return tokIf; } then { return tokThen; } else { return tokElse; } command { return tokCommand; } goto { return tokGoto; } not { return tokNot; } setup { return tokSetup; } enter { return tokEnter; } and { return tokAnd; } or { return tokOr; } true { yylval->bValue = true; return tokBool; } false { yylval->bValue = false; return tokBool; } null { return tokNull; } "<<" { BEGIN( sitname ); } [- a-zA-Z0-9]+ { yylval->sValue = new Bu::String( yytext ); return tokSituationName; } ">>" { BEGIN( INITIAL ); } . REJECT; "//"[^\n]* {} "/\*" { BEGIN( comment ); } "\*/" { BEGIN( INITIAL ); } . {} [a-zA-Z_][a-zA-Z0-9_]* { yylval->sValue = new Bu::String( yytext ); return tokIdent; } [1-9][0-9]* { yylval->iValue = strtoll( yytext, NULL, 10 ); return tokInt; } 0 { yylval->iValue = 0; return tokInt; } ([1-9][0-9]*)?\.[0-9]* { printf("Parsing float: %s\n", yytext ); yylval->dValue = strtod( yytext, NULL ); printf("Final float: %f\n", yylval->dValue ); return tokFloat; } \"\"\" { BEGIN( tdqstr ); yylval->sValue = new Bu::String(); } [^"]+ { (*yylval->sValue) += yytext; } \" { (*yylval->sValue) += yytext; } \"\"\" { BEGIN( INITIAL ); return tokString; } \'\'\' { BEGIN( tsqstr ); yylval->sValue = new Bu::String(); } [^']+ { (*yylval->sValue) += yytext; } \' { (*yylval->sValue) += yytext; } \'\'\' { BEGIN( INITIAL ); return tokString; } \" { BEGIN( dqstr ); yylval->sValue = new Bu::String(); } [^"]+ { (*yylval->sValue) += yytext; } \" { BEGIN( INITIAL ); return tokString; } \' { BEGIN( sqstr ); yylval->sValue = new Bu::String(); } [^']+ { (*yylval->sValue) += yytext; } \' { BEGIN( INITIAL ); return tokString; } [ \t]+ { yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column+1; } \n+ { yylloc->last_column = yylloc->first_column = 0; yylloc->last_line+= yyleng; yylloc->first_line = yylloc->last_line; } %%