%{
#include <ctype.h>
#include <stdio.h>
%}
%token NUMBER
%%
lines : lines expr '\n' {printf("%d\n", $2); }
| lines '\n'
|
;
expr : expr '+' term { $$ = $1 + $3; }
| expr '-' term { $$ = $1 - $3; }
| term
;
term : term '*' factor { $$ = $1 * $3; }
| term '/' factor { $$ = $1 * $3; }
| factor
;
factor : '(' expr ')' { $$ = $2; }
| NUMBER
;
%%
int yylex() {
int c;
c = getchar();
if (isdigit(c)) {
ungetc(c, stdin);
scanf("%d", &yylval);
return NUMBER;
}
return c;
}