fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. 0 {
  7. if (yytext[0] == '0') {
  8. if (current_state == 0) current_state = 2;
  9. else if (current_state == 1) current_state = 3;
  10. else if (current_state == 2) current_state = 0;
  11. else if (current_state == 3) current_state = 1;
  12. }
  13. }
  14.  
  15. 1 {
  16. if (yytext[0] == '1') {
  17. if (current_state == 0) current_state = 1;
  18. else if (current_state == 1) current_state = 0;
  19. else if (current_state == 2) current_state = 3;
  20. else if (current_state == 3) current_state = 2;
  21. }
  22. }
  23.  
  24. \n ;
  25. . ;
  26.  
  27. %%
  28.  
  29. int current_state = 0;
  30.  
  31. int main() {
  32. current_state = 0; // Start state: q0
  33.  
  34. printf("Enter a string of 0s and 1s: ");
  35. yylex(); // Start lexing
  36.  
  37. if (current_state == 1) {
  38. printf("Accepted\n");
  39. } else {
  40. printf("Not Accepted\n");
  41. }
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout #stderr 0.03s 6840KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Jlw2be/prog:2:1: Syntax error: Operator expected
ERROR: /home/Jlw2be/prog:44:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit