fork download
  1. //<parser.l>
  2. %{
  3. #include<stdio.h>
  4. #include "y.tab.h"
  5. %}
  6. %%
  7. [0-9]+ {yylval.dval=atof(yytext);
  8. return DIGIT;
  9. }
  10. \n|. return yytext[0];
  11. %%
  12. //<parser.y>
  13. %{
  14. /*This YACC specification file generates the LALR parser for the program
  15. considered in experiment 4.*/
  16. #include<stdio.h>
  17. %}
  18. %union
  19. {
  20. double dval;
  21. }
  22. %token <dval> DIGIT
  23. %type <dval> expr
  24. %type <dval> term
  25. %type <dval> factor
  26. %%
  27. line: expr '\n' {
  28. printf("%g\n",$1);
  29. }
  30. ;
  31. expr: expr '+' term {$$=$1 + $3 ;}
  32. | term
  33. ;
  34. term: term '*' factor {$$=$1 * $3 ;}
  35. | factor
  36. ;
  37. factor: '(' expr ')' {$$=$2 ;}
  38. | DIGIT
  39. ;
  40. %%
  41. int main()
  42. {
  43. yyparse();
  44. }
  45. yyerror(char *s)
  46. {
  47. printf("%s",s);
  48. }
Success #stdin #stdout #stderr 0.02s 6980KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/MAQTy0/prog:1:4: Syntax error: Operator expected
ERROR: /home/MAQTy0/prog:48:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit