fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. void print_first(char *non_terminal) {
  6. if (strcmp(non_terminal, "E") == 0)
  7. printf("FIRST(E) = { (, id }\n");
  8. else if (strcmp(non_terminal, "E'") == 0)
  9. printf("FIRST(E') = { +, ε }\n");
  10. else if (strcmp(non_terminal, "T") == 0)
  11. printf("FIRST(T) = { (, id }\n");
  12. else if (strcmp(non_terminal, "T'") == 0)
  13. printf("FIRST(T') = { *, ε }\n");
  14. else if (strcmp(non_terminal, "F") == 0)
  15. printf("FIRST(F) = { (, id }\n");
  16. else
  17. printf("Unknown non-terminal: %s\n", non_terminal);
  18. }
  19. %}
  20.  
  21. %%
  22. [A-Z][']? { print_first(yytext); }
  23. [ \t\n]+ { /* skip whitespace */ }
  24. . { printf("Invalid input: %s\n", yytext); }
  25. %%
  26.  
  27. int main() {
  28. printf("Enter non-terminals (e.g., E T E' F):\n");
  29. yylex();
  30. return 0;
  31. }
  32.  
Success #stdin #stdout #stderr 0.02s 6968KB
stdin
E
stdout
Standard output is empty
stderr
ERROR: /home/3Z01hC/prog:2:1: Syntax error: End of file in quoted string
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit