7 #define YYSTYPE struct ast *
13 void yyerror(struct ast **result, const char *str)
15 fprintf(stderr, "error: %s\n", str);
25 %token INTEGER PLUS MINUS TIMES DIVIDE BOPEN BCLOSE SEMICOLON
26 %parse-param { struct ast **result }
30 start : exprs { *result = $1; } ;
34 | exprs expr SEMICOLON { $$ = ast_cons($2, $1); }
38 : expr PLUS fact { $$ = ast_binop($1, plus, $3); }
39 | expr MINUS fact { $$ = ast_binop($1, minus, $3); }
44 : fact TIMES basic { $$ = ast_binop($1, times, $3); }
45 | fact DIVIDE basic { $$ = ast_binop($1, divide, $3); }
51 | BOPEN expr BCLOSE { $$ = $2; }