fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. void yyerror(const char *s);
  5. int yylex(void);
  6. %}
  7.  
  8. %token INTEGER
  9. %left '+' '-'
  10. %left '*' '/'
  11.  
  12. %%
  13. S:
  14. E '\n' { printf("Accepted\n"); exit(0); }
  15. ;
  16.  
  17. E:
  18. E '+' T { /* do nothing */ }
  19. | E '-' T { /* do nothing */ }
  20. | T
  21. ;
  22.  
  23. T:
  24. T '*' F { /* do nothing */ }
  25. | T '/' F { /* do nothing */ }
  26. | F
  27. ;
  28.  
  29. F:
  30. '(' E ')'
  31. ;
  32. %%
  33.  
  34. void yyerror(const char *s) {
  35. printf("%s - Invalid String\n", s);
  36. exit(1);
  37. }
  38.  
  39. int main() {
  40. printf("Enter expression: ");
  41. yyparse();
  42. return 0;
  43. }
  44.  
Success #stdin #stdout #stderr 0.03s 6948KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/OSuTFF/prog:44:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit