%%
input:
/* empty */
| input line
;
line:
'\n'
| expr '\n' { printf("Result: %f\n", $1); }
;
expr:
| expr '+' expr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; }
| expr '*' expr { $$ = $1 * $3; }
| expr '/' expr { $$ = $1 / $3; }
| '(' expr ')' { $$ = $2; }
| SIN '(' expr
')' { $$
= sin($
3); } | COS '(' expr
')' { $$
= cos($
3); } | TAN '(' expr ')' { $$ = tan($3); }
| EXP '(' expr
')' { $$
= exp($
3); } | LN
'(' expr
')' { $$
= log($
3); } ;
%%
JSUKaW5wdXQ6CiAgICAvKiBlbXB0eSAqLwogICAgfCBpbnB1dCBsaW5lCiAgICA7CgpsaW5lOgogICAgJ1xuJwogICAgfCBleHByICdcbicgeyBwcmludGYoIlJlc3VsdDogJWZcbiIsICQxKTsgfQogICAgOwoKZXhwcjoKICAgIE5VTUJFUgogICAgfCBleHByICcrJyBleHByIHsgJCQgPSAkMSArICQzOyB9CiAgICB8IGV4cHIgJy0nIGV4cHIgeyAkJCA9ICQxIC0gJDM7IH0KICAgIHwgZXhwciAnKicgZXhwciB7ICQkID0gJDEgKiAkMzsgfQogICAgfCBleHByICcvJyBleHByIHsgJCQgPSAkMSAvICQzOyB9CiAgICB8ICcoJyBleHByICcpJyAgeyAkJCA9ICQyOyB9CiAgICB8IFNJTiAnKCcgZXhwciAnKScgeyAkJCA9IHNpbigkMyk7IH0KICAgIHwgQ09TICcoJyBleHByICcpJyB7ICQkID0gY29zKCQzKTsgfQogICAgfCBUQU4gJygnIGV4cHIgJyknIHsgJCQgPSB0YW4oJDMpOyB9CiAgICB8IFNRUlQgJygnIGV4cHIgJyknIHsgJCQgPSBzcXJ0KCQzKTsgfQogICAgfCBFWFAgJygnIGV4cHIgJyknIHsgJCQgPSBleHAoJDMpOyB9CiAgICB8IExOICcoJyBleHByICcpJyB7ICQkID0gbG9nKCQzKTsgfQogICAgOwolJQo=