fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int yylex(void);
  5. void yyerror(const char *s);
  6. %}
  7.  
  8. %token A B C
  9.  
  10. %%
  11.  
  12. S : A S B
  13. | B S A
  14. | C
  15. ;
  16.  
  17. %%
  18.  
  19. int yylex()
  20. {
  21. int ch;
  22.  
  23. ch = getchar();
  24.  
  25. if (ch == 'a')
  26. return A;
  27. if (ch == 'b')
  28. return B;
  29. if (ch == 'c')
  30. return C;
  31.  
  32. return 0;
  33. }
  34.  
  35. void yyerror(const char *s)
  36. {
  37. printf("Invalid string\n");
  38. }
  39.  
  40. int main()
  41. {
  42. printf("Enter string: ");
  43.  
  44. if (yyparse() == 0)
  45. printf("Valid string\n");
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout #stderr 0.02s 6740KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/JyHPMr/prog:48:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit