%{ /*C declarations */ #define YYDEBUG 1 %} %token INTEGER EOL %% /* the grammar section */ line: exp EOL { printf("%d\n", $1); } ; exp: exp '+' exp { $$ = $1 + $3; } | exp '-' exp { $$ = $1 - $3; } | INTEGER { $$ = $1; } ; %% /* as with Flex, user-supplied C code */ /* include the Flex-generated lexical analyzer */ #include "gram7.yy.c" main() { extern int yydebug; extern int yy_flex_debug; yydebug = 1; yy_flex_debug = 1; yyparse(); } int yyerror(char *s) { fprintf(stderr, "%s\n", s); return 0; }