%{ #include #include #include %} %left '-' '+' %left '*' '/' %nonassoc UMINUS %union { char* lexeme; //identifier double value; //value of an identifier of type NUM } %token NUM %token IF %token ID %type expr /* %type line */ %start line %% line : expr {printf("Result: %f\n", $1);} | line ';' expr {printf("Result: %f\n", $3);} ; expr : expr '+' expr {$$ = $1 + $3;} | expr '-' expr {$$ = $1 - $3;} | expr '*' expr {$$ = $1 * $3;} | expr '/' expr {$$ = $1 / $3;} | NUM {$$ = $1;} ; %% #include "lex.yy.c"