fork download
  1. %%
  2. input:
  3. /* empty */
  4. | input line
  5. ;
  6.  
  7. line:
  8. '\n'
  9. | expr '\n' { printf("Result: %f\n", $1); }
  10. ;
  11.  
  12. expr:
  13. | expr '+' expr { $$ = $1 + $3; }
  14. | expr '-' expr { $$ = $1 - $3; }
  15. | expr '*' expr { $$ = $1 * $3; }
  16. | expr '/' expr { $$ = $1 / $3; }
  17. | '(' expr ')' { $$ = $2; }
  18. | SIN '(' expr ')' { $$ = sin($3); }
  19. | COS '(' expr ')' { $$ = cos($3); }
  20. | TAN '(' expr ')' { $$ = tan($3); }
  21. | SQRT '(' expr ')' { $$ = sqrt($3); }
  22. | EXP '(' expr ')' { $$ = exp($3); }
  23. | LN '(' expr ')' { $$ = log($3); }
  24. ;
  25. %%
  26.  
Success #stdin #stdout #stderr 0.03s 6928KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/46AKHI/prog:26:2: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit