Docsity

Subset Construction - Compiler Construction - Lecture Slides, Slides of Compiler Construction

Partial preview of the text

Download Subset Construction - Compiler Construction - Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 8

2

NFA → DFA Construction

 The algorithm is called subset construction.  In the transition table of an NFA, each entry is a set of states.  In DFA, each entry is a single state

4

NFA → DFA Construction

 The DFA uses its state to keep track of all possible states the NFA can be in after reading each input symbol.

5

NFA → DFA Construction

 We will use the following operations.  ε -closure(T) : set of NFA states reachable from some NFA state s in T on ε-transitions alone.

7

NFA → DFA Construction

 Before it sees the first input symbol, NFA can be in any of the state in the set ε -closure(s 0 ) , where s 0 is the start state of the NFA.

8

NFA → DFA Construction

 Suppose that exactly the states in set T are reachable from s 0 on a given sequence of input symbols.

10

NFA → DFA Construction

 Let a be the next input symbol.  On seeing a , the NFA can move to any of the states in the set move(T,a).

11

NFA → DFA Construction

 When we allow for ε-transitions, NFA can be in any of the states in

ε -closure(move(T,a))

after seeing a.

13

Subset Construction

Output:

DFA D with state set S’,

alphabet Σ, start states

s 0 ’ = ε-closure(s 0 ), final

states F’, transition

table: S’ x Σ → S’

14

Algorithm

// initially, e-closure(s 0 ) is the only // state in D states S’ and it is // unmarked s 0 ’ = ε-closure( s 0 ) S’ = { s 0 ’ } (unmarked)

16

Algorithm

F’: for each DFA state S if S contains an NFA final state mark S as DFA final state

17

Subset Construction Example

NFA for ( a | b )abb*

0 ε^

ε

ε ε

ε

a

b

ε

ε

1

2 3

4 5

6 ε^7 a^ 8 b^ 9 b^ 10

19

A = {0,1,2,4,7}, these are exactly the states reachable from state 0 via ε-transition.

ε 0 ε^

ε

ε ε

ε

a

b ε

1

(^2 )

4 5

6 ε^7 a^ 8 b^ 9 b^ 10

ε

20

 The input symbol alphabet here is { a , b }.

ε

0 ε^

ε

ε ε

ε

a

b ε

1

(^2 )

4 5

6 ε^7 a^ 8 b^ 9 b^ 10

ε