%{ #include #define YYERROR_VERBOSE void yyerror(char *); %} %token NUMBER ILLEGAL_CHAR %left '-' '+' %left '*' '/' %% eingabe: /* empty */ | eingabe berechnung ; berechnung: term '=' { printf("Ergebnis: %d\n", $1); } ; term: NUMBER | term '+' term { $$ = $1 + $3; } | term '-' term { $$ = $1 - $3; } | term '*' term { $$ = $1 * $3; } | term '/' term { $$ = $1 / $3; } | '(' term ')' { $$ = $2; } ; %% void yyerror(char *msg) { printf("\nEingabefehler: %s\n", msg); } int main() { return yyparse(); }