%{ #include #include "node.hpp" #include "grammar.hpp" #define YYLEX grammarlex #define SAVE_TOKEN grammarlval.string = new std::string( yytext, yyleng ) #define DEBUG( what ) std::cerr << "DEBUG: " << what << " '" << yytext << "'" << std::endl #define TOKEN( t ) ( grammarlval.token = t ) %} %% [ \t\n] ; [a-zA-Z_][a-zA-Z0-9_]* DEBUG( "TIDENTIFIER" ); SAVE_TOKEN; return TIDENTIFIER; [0-9]+ DEBUG( "TINTEGER" ); SAVE_TOKEN; return TINTEGER; "(" DEBUG( "TLPAREN" ); return TOKEN( TLPAREN ); ")" DEBUG( "TRPAREN" ); return TOKEN( TRPAREN ); "{" DEBUG( "TLBRACE" ); return TOKEN( TLBRACE ); "}" DEBUG( "TRBRACE" ); return TOKEN( TRBRACE ); "=" DEBUG( "TEQUAL" ); return TOKEN( TEQUAL ); "*" DEBUG( "TMUL" ); return TOKEN( TMUL ); "+" DEBUG( "TPLUS" ); return TOKEN( TPLUS ); "," DEBUG( "TCOMMA" ); return TOKEN( TCOMMA ); "//".* // ignore comments; . std::cerr << "ERROR: Unknown token '" << yytext << "'" << std::endl; yyterminate( ); %% int grammarwrap( void ) { return 1; }