fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. %token A B
  7.  
  8. %%
  9.  
  10. S : A B { printf("Valid string: a^n b^n\n"); }
  11. | A S B { /* Recursive rule to match a^n b^n */ }
  12. | { /* epsilon rule */ }
  13. ;
  14.  
  15. %%
  16.  
  17. int main(void) {
  18. printf("Enter string of a's and b's: ");
  19. yyparse();
  20. return 0;
  21. }
  22.  
  23. int yyerror(char *s) {
  24. printf("Error: %s\n", s);
  25. return 0;
  26. }
  27.  
Success #stdin #stdout #stderr 0.02s 6924KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/NkRfit/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit