fork download
  1. %{
  2. /* Definition section */
  3. #include<stdio.h>
  4. #include <stdlib.h>
  5. void yyerror(const char *str)
  6. {
  7. printf("\nSequence Rejected\n");
  8. }
  9.  
  10. %}
  11.  
  12. %token ZERO ONE
  13.  
  14. /* Rule Section */
  15. %%
  16.  
  17. r : s {printf("\nSequence Accepted\n\n");}
  18. ;
  19.  
  20. s : n
  21. | ZERO a
  22. | ONE b
  23. ;
  24.  
  25. a : n a
  26. | ZERO
  27. ;
  28.  
  29. b : n b
  30. | ONE
  31. ;
  32.  
  33. n : ZERO
  34. | ONE
  35. ;
  36.  
  37. %%
  38.  
  39. #include"lex.yy.c"
  40. //driver code
  41. int main()
  42. {
  43. printf("\nEnter Sequence of Zeros and Ones : ");
  44. yyparse();
  45. printf("\n");
  46. return 0;
  47. }
  48.  
Success #stdin #stdout #stderr 0.02s 6860KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/gpRIKe/prog:47:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit