Compiler: by Noor Wali Khan Uoch
Compiler: by Noor Wali Khan Uoch
D={1,2,4,5,6,7,9} B B D
E={1,2,4,5,6,7,10} C B C
D B E
A is start state E B C
E is accepting state
Final Transition Table
2
a
b b
B D E
a
A a
b
b
Input symbol
State
a b
C
A B C
B B D
C B C
b
D B E
E B C
3
DFA Minimization
• The generated DFA may have a large number of states.
4
b
b b
B D E
a
A a
b
b
Input symbol
State
a b
C
A B C
B B D
C B C
b
D B E
E B C
5
a
a
B
b
a b
D E
b
a
A, C
Input symbol
State a b
b A B C
B B D
C B C
D B E
E B C
6
Exercise:
RE -> NFA -> DFA
7
a (a | c)* b
8
ε-closure Computation
ε-closure(0) = {0} = S0
ε-closure(move(S0, a)) = ε-closure({1}) = {1,2,3,5,8} = S1
ε-closure(move(S0, b)) = ε-closure({}) = no state
ε-closure(move(S0, c)) = ε-closure({}) = no state
ε-closure(move(S1, a)) = ε-closure({4}) = {4,7,8,2,3,5} = S2
ε-closure(move(S1, b)) = ε-closure({9}) = {9} = S3
ε-closure(move(S1, c)) = ε-closure({6}) = {6,7,8,2,3,5} = S4
ε-closure(move(S2, a)) = ε-closure({4}) = S2
ε-closure(move(S2, b)) = ε-closure({9}) = S3
ε-closure(move(S2, c)) = ε-closure({6}) = S4
ε-closure(move(S3, a)) = ε-closure({}) = no state
ε-closure(move(S3, b)) = ε-closure({}) = no state
ε-closure(move(S3, c)) = ε-closure({}) = no state
ε-closure(move(S4, a)) = ε-closure({4}) = S2
ε-closure(move(S4, b)) = ε-closure({9}) = S3
ε-closure(move(S4, c)) = ε-closure({6}) = S4
9
DFA
State a b c
S0 S1 - - Initial
S1 S2 S3 S4
S2 S2 S3 S4
S3 - - - Final
S4 S2 S3 S4
10
Grouping and Removal of similar
states for minimization
State a b c
State a b c
S0 S1 - - Initial
S0 S1 - - Initial
S1 S2 S3 S4 S1 S1 S3 S1
S2 S2 S3 S4 S2 S2 S3 S4
S4 S2 S3 S4
S3 - - - Final
S3 - - - Final
S4 S2 S3 S4
a (a | c)* b
11