/* File: ch3-01.y (modified from lex & yacc book by John Levine) */ %{ #include %} %token NAME NUMBER %% statement: NAME '=' expression | expression { printf("= %d\n", $1); } ; expression: expression '+' NUMBER { $$ = $1 + $3; } | expression '-' NUMBER { $$ = $1 - $3; } | NUMBER { $$ = $1; } ; %% main() { yyparse() ; }