Deterministic Finite Automata: - A Deterministic Finite Automata (DFA, For Short) Is A Special Case of NDFA in Which
Deterministic Finite Automata: - A Deterministic Finite Automata (DFA, For Short) Is A Special Case of NDFA in Which
A Deterministic finite automata (DFA, for short) is a special case of NDFA in which
No state has e transition For each state s and an input symbol a, there is at most one edge labeled a leaving s
Simulating a DFA:
Example
Computation of Substates
e-closure A = {0,1,2,4,7} e-closure move(A,a)) e-closure({3,8}) B= { 1,2,3,4,6,7,8} ie Dtran[A,a] = B
Dtran[A,b] e-closure({5])= {1,2,4,5,6,7}=C Five different states are A = { 0,1,2,4,7 } D = { 1,2,4,5,6,7,9 } B = { 1,2,3,4,6,7,8 } E = { 1,2,4,5,6,7,10 } C = { 1,2,4,5,6,7 }
A regular expression
Nondeterministic FA
Deterministic FA
Example
Construct an NFA for regular expression (a|b)*abb
For r1
For r2
NFA for r3 = r1 | r2
01*|1 (0(1*))|1
1*
start
01*
start
1
0 1
01*|1 start
1 3
1 3
d 2 0 D
1 3
. 4
D 5
2 0 D 1 3 . 4 D 5
12
6
D
13
10
D
9
11
0 14
Move({1,3,4,5,12},.} = {6}
DFA State 2 = {6}
-closure ({6})= {6}
Move({6},.} =
Move({6},D} = {7}
Move({1,2,4,8},.} = {6,10}
DFA State 3 = {7} -closure ({7})= {7,13,14}
Move({7,13,14},D} =
Move({7,13,14},.} =
state 6)
DFA States 3 and 5 are accepting states because their e-closure sets contain the an accepting state (NFA state 14)
Move({7,9,11,13,14},.} =
Move({9,11,13,14},D} = {11}
2 . 4
D
D
D . D
D 5 6
D 7
2 . 4
Minimizing D
3
D
D .
D 5
Exercises:
1. Write a lexical analyzer that processes the PL/1 statement
if then then then = else ; else else else = then;
2. Write a regular expression that recognizes all possible integer constants in C 3. Write a regular expression that recognizes a C identifier. Construct an NFA to this expression, convert into DFA and minimize
Exercises:
Page 147 3.6 3.7 & 3.11