%token NAME NUMBER %start statement %% statement: NAME '=' expression { $$ = $1; printf("(%d)\n", $3); } | expression { $$ = $1; printf("= %d\n", $1); } ; expression: expression '+' NUMBER { $$ = $1 + $3; } | expression '-' NUMBER { $$ = $1 - $3; } | NUMBER { $$ = $1; } ; %% #include extern FILE *yyin; yyerror(s) char *s; { fprintf(stderr,"%d\n",s); } main () { do { yyparse(); } while (!feof(yyin)); }