%{ #include #include void yyerror( const char *msg); /* called for parser syntax error */ int yylex( void); /* declare to avoid gcc warnings */ #define YYSTYPE double %} %token NUMBER %% list: /* nothing, matches before start of input */ | list '\n' /* empty line */ | list expression '\n' { printf( "%g\n", $2); } | list error '\n' { yyerrok; } ; primary_expression: NUMBER | '(' expression ')' { $$ = $2; } ; multiplicative_expression: primary_expression | multiplicative_expression '*' primary_expression { $$ = $1 * $3; } ; additive_expression: multiplicative_expression | additive_expression '+' multiplicative_expression { $$ = $1 + $3; } ; expression: additive_expression ; %% int main( int argc, char *argv[]) { return yyparse(); }