//design a dfa index using state diagram that accepts input string of pattern ending with 10 and should contain a substring 11. -9/02
%{
#include <stdio.h>
%}
%s s1 s2 s3 DEAD
%%
<INITIAL>0 { BEGIN(INITIAL); }
<INITIAL>1 { BEGIN(s1); }
<s1>0 { BEGIN(INITIAL); }
<s1>1 { BEGIN(s2); }
<s2>0 { BEGIN(s3); }
<s2>1 { BEGIN(s2); }
<s3>0 { BEGIN(s3); }
<s3>1 { BEGIN(s2); }
<INITIAL>[^01\n] { BEGIN(DEAD); }
<s1>[^01\n] { BEGIN(DEAD); }
<s2>[^01\n] { BEGIN(DEAD); }
<s3>[^01\n] { BEGIN(DEAD); }
<INITIAL>\n { printf("Not accepted\n"); BEGIN(INITIAL); }
<s1>\n { printf("Not accepted\n"); BEGIN(INITIAL); }
<s2>\n { printf("Not accepted\n"); BEGIN(INITIAL); }
<s3>\n { printf("Accepted\n"); BEGIN(INITIAL); }
<DEAD>[^ \n]* { }
<DEAD>\n { printf("Invalid input\n"); BEGIN(INITIAL); }
%%
int yywrap(){ return 1; }
int main(){ yylex(); return 0; }
/*
OUTPUT:
geu@CSITLAB1-56:~/mnx$ lex endingwith10andsubtring11.l
geu@CSITLAB1-56:~/mnx$ gcc lex.yy.c
geu@CSITLAB1-56:~/mnx$ ./a.out
0010
Not accepted
0110
Accepted
090901
Invalid input
11111110
Accepted
101010
Not accepted
000110
Accepted
*/