fork download
  1. %{
  2. /* This LEX program returns the tokens for the expression */
  3. #include "y.tab.h"
  4. %}
  5. %%
  6. "=" {printf("\n Operator is EQUAL");}
  7. "+" {printf("\n Operator is PLUS");}
  8. "-" {printf("\n Operator is MINUS");}
  9. "/" {printf("\n Operator is DIVISION");}
  10. "*" {printf("\n Operator is MULTIPLICATION");}
  11. [a-zA-Z]*[0-9]* {
  12. printf("\n Identifier is %s",yytext);
  13. return ID; }
  14. . return yytext[0];
  15. \n return 0;
  16. %%
  17. int yywrap()
  18. {
  19. return 1;
  20. }
  21. Program name:ex3.y
  22. %{
  23. #include<stdio.h>
  24. /* This YACC program is for recognizing the Expression */
  25. %}
  26. %token A ID
  27. %%
  28. statement: A'='E
  29. | E {
  30. printf("\n Valid arithmetic expression");
  31. $$=$1;
  32. }
  33. ;
  34. E: E'+'ID
  35. | E'-'ID
  36. | E'*'ID
  37. | E'/'ID
  38. | ID
  39. ;
  40. %%
  41. extern FILE*yyin;
  42. main() {
  43. do {
  44. yyparse();
  45. }while(!feof(yyin)); }
  46. yyerror(char*s)
  47. {
  48. }
Success #stdin #stdout #stderr 0.02s 7008KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/fs2gts/prog:3:1: Syntax error: Operator expected
ERROR: /home/fs2gts/prog:48:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit