0% found this document useful (0 votes)
40 views11 pages

Compiler: by Noor Wali Khan Uoch

The document describes the process of constructing a deterministic finite automaton (DFA) from a regular expression. It first defines the epsilon-closure sets for each state reached from the starting state based on the symbols in the regular expression. It then constructs the transition table for the DFA based on these epsilon-closure sets. Finally, it applies DFA minimization to reduce the number of states by grouping equivalent states.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views11 pages

Compiler: by Noor Wali Khan Uoch

The document describes the process of constructing a deterministic finite automaton (DFA) from a regular expression. It first defines the epsilon-closure sets for each state reached from the starting state based on the symbols in the regular expression. It then constructs the transition table for the DFA based on these epsilon-closure sets. Finally, it applies DFA minimization to reduce the number of states by grouping equivalent states.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Compiler

By Noor wali khan


UOCH
Subset Construction

Eventually, the 5 sets are:


Input symbol
A={0,1,2,4,7} State
a b
B={1,2,3,4,6,7,8}
C={1,2,4,5,6,7} A B C

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.

• Hopcroft’s algorithm: minimizes DFA states

• Idea: find groups of equivalent states.

• All transitions from states in one group G1 go to states in


the same group G2

• Construct the minimized DFA such that there is one state


for each group of states from the initial DFA.

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

Convert the regular expression


a (a | c)* b
To DFA using by Thompson Construction Method

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

You might also like