%option noyywrap outfile="simple_lexer.c" /* scanner for a toy calculator simple_lexer.l */ %{ #include "Expr.h" /* required for the types in next line */ #include "simple_parser.tab.h" /* token definitions and types */ %} %% [0-9]+ yylval.intval = atoi(yytext); return TOK_NUMBER; if return TOK_IF; then return TOK_THEN; else return TOK_ELSE; [a-z][a-z0-9]* yylval.string = strdup(yytext); return TOK_ID; [ \t]+ /* eat up whitespace */ [+\-*/()\n] { return yytext[0];} . fprintf(stderr, "Unrecognized character: %s\n", yytext ); return -1;