/* scanner for a toy Pascal-like language */ %{ /* need this for the call to atof() below */ #include #include "tok.h" int yyparse(); int yyerror( char * s); int yylineno = 1; int tempint; %} DIGIT [0-9] ID [a-z][a-z0-9]* %% {DIGIT}+ { sscanf(yytext, "%d", &tempint); yylval.int_val = tempint; return NUM; } "+" { return PLUS; } "-" { return MINUS; } "*" { return MULT; } "/" { return DIV; } "{"[^}\n]*"}" /* eat up one-line comments */ [ \t ]* /* eat up whitespace */ [\n] { ++yylineno; } . { return yytext[0]; } %% int main( int argc, char ** argv ) { ++argv, --argc; if ( argc > 0 ) yyin = fopen( argv[0], "r" ); else yyin = stdin; // yylex(); yyparse(); }