/* File: postfix.y */ %{ #include %} %token NAME NUMBER %% statement: NAME '=' expression | expression { printf("\n") ; } ; expression: expression '+' term { printf("+ ") ; } | expression '-' term { printf("- ") ; } | term { /* do nothing */ } ; term: term '*' factor { printf("* ") ; } | term '/' factor { printf("/ ") ; } | factor { /* do nothing */ } ; factor: '(' expression ')' { /* do nothing */ } | NUMBER { printf("%d ", $1) ; } ; %% main() { yyparse() ; }