fork download
  1. //design a dfa index using state diagram that accepts input string of pattern ending with 10 and should contain a substring 11. -9/02
  2.  
  3. %{
  4. #include <stdio.h>
  5. %}
  6.  
  7. %s s1 s2 s3 DEAD
  8.  
  9. %%
  10.  
  11. <INITIAL>0 { BEGIN(INITIAL); }
  12. <INITIAL>1 { BEGIN(s1); }
  13.  
  14. <s1>0 { BEGIN(INITIAL); }
  15. <s1>1 { BEGIN(s2); }
  16.  
  17. <s2>0 { BEGIN(s3); }
  18. <s2>1 { BEGIN(s2); }
  19.  
  20. <s3>0 { BEGIN(s3); }
  21. <s3>1 { BEGIN(s2); }
  22.  
  23. <INITIAL>[^01\n] { BEGIN(DEAD); }
  24. <s1>[^01\n] { BEGIN(DEAD); }
  25. <s2>[^01\n] { BEGIN(DEAD); }
  26. <s3>[^01\n] { BEGIN(DEAD); }
  27.  
  28. <INITIAL>\n { printf("Not accepted\n"); BEGIN(INITIAL); }
  29. <s1>\n { printf("Not accepted\n"); BEGIN(INITIAL); }
  30. <s2>\n { printf("Not accepted\n"); BEGIN(INITIAL); }
  31. <s3>\n { printf("Accepted\n"); BEGIN(INITIAL); }
  32.  
  33. <DEAD>[^ \n]* { }
  34. <DEAD>\n { printf("Invalid input\n"); BEGIN(INITIAL); }
  35.  
  36. %%
  37.  
  38. int yywrap(){ return 1; }
  39.  
  40. int main(){ yylex(); return 0; }
  41.  
  42. /*
  43. OUTPUT:
  44. geu@CSITLAB1-56:~/mnx$ lex endingwith10andsubtring11.l
  45. geu@CSITLAB1-56:~/mnx$ gcc lex.yy.c
  46. geu@CSITLAB1-56:~/mnx$ ./a.out
  47. 0010
  48. Not accepted
  49. 0110
  50. Accepted
  51. 090901
  52. Invalid input
  53. 11111110
  54. Accepted
  55. 101010
  56. Not accepted
  57. 000110
  58. Accepted
  59.  
  60. */
Success #stdin #stdout #stderr 0.02s 6940KB
stdin
abc
stdout
Standard output is empty
stderr
ERROR: /home/NxNjlX/prog:1:3: Syntax error: Operator expected
ERROR: /home/NxNjlX/prog:60:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit