-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_DFA_Third_Last_a.l
51 lines (51 loc) · 1.21 KB
/
10_DFA_Third_Last_a.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*Design a DFA in LEX Code which accepts string containing third last element 'a' over input alphabet {a,b}.*/
%{
#include<stdio.h>
%}
%s q1 q2 q3 q4 q5 q6 q7 DEAD
%%
<INITIAL>a BEGIN q1;
<INITIAL>b BEGIN INITIAL;
<INITIAL>[^ab\n] BEGIN DEAD;
<INITIAL>\n BEGIN INITIAL; {printf("Not accepted\n");}
<q1>a BEGIN q2;
<q1>b BEGIN q5;
<q1>[^ab\n] BEGIN DEAD;
<q1>\n BEGIN INITIAL; {printf("Not accepted\n");}
<q2>a BEGIN q3;
<q2>b BEGIN q4;
<q2>[^ab\n] BEGIN DEAD;
<q2>\n BEGIN INITIAL; {printf("Not accepted\n");}
<q3>a BEGIN q3;
<q3>b BEGIN q4;
<q3>\n BEGIN INITIAL; {printf("accepted\n");}
<q3>[^ba\n] BEGIN DEAD;
<q4>a BEGIN q6;
<q4>b BEGIN q7;
<q4>\n BEGIN INITIAL; {printf("accepted\n");}
<q4>[^ba\n] BEGIN DEAD;
<q5>a BEGIN q6;
<q5>b BEGIN q7;
<q5>[^ab\n] BEGIN DEAD;
<q5>\n BEGIN INITIAL; {printf("Not accepted\n");}
<q6>a BEGIN q2;
<q6>b BEGIN q5;
<q6>\n BEGIN INITIAL; {printf("accepted\n");}
<q6>[^ba\n] BEGIN DEAD;
<q7>a BEGIN q1;
<q7>b BEGIN INITIAL;
<q7>\n BEGIN INITIAL; {printf("accepted\n");}
<q7>[^ba\n] BEGIN DEAD;
<DEAD>[^\n] BEGIN DEAD;
<DEAD>\n BEGIN INITIAL; {printf("Invalid\n");}
%%
int yywrap()
{
return 1;
}
int main()
{
printf("Enter String\n");
yylex();
return 0;
}