fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %define INITIAL 0
  6. %define SAW_A 1
  7. %define SAW_AB 2
  8. %define SAW_ABA 3
  9.  
  10. %%
  11.  
  12. /* Define transitions for 'a' and 'b' */
  13. a {
  14. if (state == INITIAL) state = SAW_A; /* Transition from q0 to q1 */
  15. else if (state == SAW_A) state = SAW_A; /* Stay in q1 */
  16. else if (state == SAW_AB) state = SAW_ABA; /* Transition from q2 to q3 */
  17. }
  18.  
  19. b {
  20. if (state == INITIAL) state = INITIAL; /* Stay in q0 */
  21. else if (state == SAW_A) state = SAW_AB; /* Transition from q1 to q2 */
  22. else if (state == SAW_AB) state = INITIAL;/* Transition from q2 to q0 (reset) */
  23. else if (state == SAW_ABA) state = SAW_ABA;/* Stay in q3 */
  24. }
  25.  
  26. . /* Ignore any other characters */
  27.  
  28. %%
  29.  
  30. /* Main function to drive the Lex program */
  31. int main() {
  32. int state = INITIAL; /* Start in state q0 */
  33.  
  34. yylex(); /* Invoke Lex to process the input */
  35.  
  36. if (state == SAW_ABA) {
  37. printf("Input string contains the substring 'aba'.\n");
  38. } else {
  39. printf("Input string does not contain the substring 'aba'.\n");
  40. }
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout #stderr 0.03s 6808KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/ikcXFa/prog:2:1: Syntax error: Operator expected
ERROR: /home/ikcXFa/prog:43:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit