%{ #include #include int yywrap( ); void yyerror(const char* str); %} %token VAL %token PLUS %token MINUS %token DIVIDE %token TIMES %token LEFT %token RIGHT %token DONE /* give us more detailed errors */ %error-verbose %% /* one expression only followed by a new line */ stmt: expr DONE {return 0;} /* an expression uses + or - or neither */ expr: expr PLUS term {} | expr MINUS term {} | term {} /* an expression uses * or / or neither */ term: term TIMES factor {} | term DIVIDE factor {} | factor {} factor: VAL {} | LEFT expr RIGHT {} %% int yywrap( ) { return 1; } void yyerror(const char* str) { fprintf(stderr, "Compiler error: '%s'.\n", str); } int main( ) { yyparse( ); return 0; }