2 * expr.y : A simple yacc expression parser
3 * Based on the Bison manual example.
17 %token PLUS MINUS MULT DIV EXPON
25 %type
<val
> exp NUMBER
33 | exp EOL
{ printf
("%g\n",$1);}
35 exp
: NUMBER
{ $$
= $1; }
36 | exp PLUS exp
{ $$
= $1 + $3; }
37 | exp MINUS exp
{ $$
= $1 - $3; }
38 | exp MULT exp
{ $$
= $1 * $3; }
39 | exp DIV exp
{ $$
= $1 / $3; }
40 | MINUS exp %prec MINUS
{ $$
= -$2; }
41 | exp EXPON exp
{ $$
= pow
($1,$3);}
42 | LB exp RB
{ $$
= $2; }
47 yyerror(char *message
)
49 printf
("%s\n",message
);
52 int main
(int argc
, char *argv
[])