Converting an NFA to a DFA

350 downloads 11341 Views 349KB Size Report
Convert to an equivalent deterministic finite state machine (DFA). Why? ... IDEA: Each state in the DFA will correspond to a set of NFA states. Worst-case:.
Lexical Analysis - Part 3

Converting an NFA to a DFA Given: A non-deterministic finite state machine (NFA) Goal: Convert to an equivalent deterministic finite state machine (DFA) Why? Faster recognizer! Approach: Consider simulating a NFA. Work with sets of states. IDEA: Each state in the DFA will correspond to a set of NFA states. Worst-case: There can be an exponential number O(2N) of sets of states. The DFA can have exponentially many more states than the NFA ... but this is rare. © Harry H. Porter, 2005

1

Lexical Analysis - Part 3

NFA to DFA Input: A NFA

S = States = { s0, s1, ..., sN} = SNFA ! = Move function = MoveNFA Move’(S, a) " Set of states

Output: A DFA

S = States = {?, ?, ..., ?} = SDFA ! = Move function = MoveDFA Move(s, a) " Single state from SDFA

Main Idea:

Each state in SDFA will be a set of states from the NFA SDFA = { {...}, {...} , ..., {...} }

3

5 7

a a

{3}

NFA

a

{5,7}

DFA

(The names of the states is arbitrary and can be changed later, if desired.)

1 © Harry H. Porter, 2005

a

2 2

Lexical Analysis - Part 3

Algorithm: Convert NFA to DFA We’ll use... MoveNFA(S,a) #-Closure(s) #-Closure(S)

the transition function from NFA where s is a single state from NFA where S is a set of states from NFA

We’ll construct... SDFA the set of states in the DFA Initially, we’ll set SDFA to {} Add X to SDFA where X is some set of NFA states Example: “Add {3,5,7} to SDFA” We’ll “mark” some of the states in the DFA. Marked = “We’ve done this one” ($) Unmarked = “Still need to do this one” The transition function from DFA To add an edge to the growing DFA...

MoveDFA(T,b)

Set MoveDFA(T,b) to S b

T

S

...where S and T are sets of NFA states © Harry H. Porter, 2005

3

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) =

© Harry H. Porter, 2005

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

4

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7}

2 4

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

© Harry H. Porter, 2005

5

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

© Harry H. Porter, 2005

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

6

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(A,a) =

MoveDFA(A,b) =

© Harry H. Porter, 2005

7

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = MoveDFA(A,b) =

© Harry H. Porter, 2005

8

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = #-Closure ({3,8}) = MoveDFA(A,b) =

© Harry H. Porter, 2005

9

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} MoveDFA(A,b) =

© Harry H. Porter, 2005

10

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(A,b) =

© Harry H. Porter, 2005

11

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(A,b) = #-Closure (MoveNFA(A,b)) =

© Harry H. Porter, 2005

12

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(A,b) = #-Closure (MoveNFA(A,b)) = #-Closure ({5}) =

© Harry H. Porter, 2005

13

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(A,b) = #-Closure (MoveNFA(A,b)) = #-Closure ({5}) = {1,2,4,5,6,7} = C

© Harry H. Porter, 2005

14

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(A,b) = #-Closure (MoveNFA(A,b)) = #-Closure ({5}) = {1,2,4,5,6,7} = C

C

b

So far:

A

B

a

© Harry H. Porter, 2005

15

Lexical Analysis - Part 3

Example 0

#

#

1 #

Start state: #-Closure (0) = {0, 1, 2, 4, 7} = A

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(A,a) = #-Closure (MoveNFA(A,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(A,b) = #-Closure (MoveNFA(A,b)) = #-Closure ({5}) = {1,2,4,5,6,7} = C So far:

$ A

© Harry H. Porter, 2005

b a

C B

A is now done; mark it! B and C are unmarked. Let’s do B next... 16

Lexical Analysis - Part 3

Example 0

#

#

1 #

2 4

Process B = {1,2,3,4,6,7,8}

$ A

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

C

b

B

a

© Harry H. Porter, 2005

17

Lexical Analysis - Part 3

Example 0

#

#

1 #

Process B = {1,2,3,4,6,7,8}

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(B,a) =

$ A © Harry H. Porter, 2005

b a

C B 18

Lexical Analysis - Part 3

Example 0

#

#

1 #

2 4

Process B = {1,2,3,4,6,7,8}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) =

$ A

C

b

B

a

© Harry H. Porter, 2005

19

Lexical Analysis - Part 3

Example 0

#

#

1 #

Process B = {1,2,3,4,6,7,8}

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) =

$ A © Harry H. Porter, 2005

b a

C B 20

Lexical Analysis - Part 3

Example 0

#

#

1 #

2 4

Process B = {1,2,3,4,6,7,8}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B

$ A

C

b

B

a

© Harry H. Porter, 2005

21

Lexical Analysis - Part 3

Example 0

#

#

1 #

Process B = {1,2,3,4,6,7,8}

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B

$ A

b a

C B a

© Harry H. Porter, 2005

22

Lexical Analysis - Part 3

Example 0

#

#

1 #

2 4

Process B = {1,2,3,4,6,7,8}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(B,b) =

$ A

C

b

B

a

a © Harry H. Porter, 2005

23

Lexical Analysis - Part 3

Example 0

#

#

1 #

Process B = {1,2,3,4,6,7,8}

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(B,b) = #-Closure (MoveNFA(B,b)) =

$ A

b a

C B a

© Harry H. Porter, 2005

24

Lexical Analysis - Part 3

Example 0

#

#

1 #

2 4

Process B = {1,2,3,4,6,7,8}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(B,b) = #-Closure (MoveNFA(B,b)) = #-Closure ({5,9}) =

$ A

C

b

B

a

a © Harry H. Porter, 2005

25

Lexical Analysis - Part 3

Example 0

#

#

1 #

Process B = {1,2,3,4,6,7,8}

2 4

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(B,b) = #-Closure (MoveNFA(B,b)) = #-Closure ({5,9}) = {1,2,4,5,6,7,9} = D

$ A

b a

C B a

© Harry H. Porter, 2005

26

Lexical Analysis - Part 3

Example 0

2

#

#

1

4

#

Process B = {1,2,3,4,6,7,8}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(B,b) = #-Closure (MoveNFA(B,b)) = #-Closure ({5,9}) = {1,2,4,5,6,7,9} = D

$ A

C

b

B

a

D

b a

© Harry H. Porter, 2005

27

Lexical Analysis - Part 3

Example 0

2

#

#

1

4

#

Process B = {1,2,3,4,6,7,8}

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(B,a) = #-Closure (MoveNFA(B,a)) = #-Closure ({3,8}) = {1,2,3,4,6,7,8} = B MoveDFA(B,b) = #-Closure (MoveNFA(B,b)) = #-Closure ({5,9}) = {1,2,4,5,6,7,9} = D

$ A

b a

C B

$ b

D

a © Harry H. Porter, 2005

28

Lexical Analysis - Part 3

Example 0

2

#

#

1

4

#

Process C = {1,2,4,5,6,7}

$ A

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

C

b

B

a

$

D

b a

© Harry H. Porter, 2005

29

Lexical Analysis - Part 3

Example 0

2

#

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(C,a) = MoveDFA(C,b) =

$ A

b a

C B

$ b

D

a © Harry H. Porter, 2005

30

Lexical Analysis - Part 3

Example 0

2

#

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) =

$ A

C

b

B

a

$

D

b a

© Harry H. Porter, 2005

31

Lexical Analysis - Part 3

Example 0

2

#

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C

$ A

b a

C B

$ b

D

a © Harry H. Porter, 2005

32

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C

b

$ A

$

C

b

a

B

a

$

D

b a

© Harry H. Porter, 2005

33

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process D = {1,2,4,5,6,7,9} MoveDFA(D,a) = MoveDFA(D,b) = b

$ A

b a

C a

B

$ $ b

D

a © Harry H. Porter, 2005

34

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process D = {1,2,4,5,6,7,9} MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = b

$ A

$

C

b

a

B

a

$

D

b a

© Harry H. Porter, 2005

35

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process D = {1,2,4,5,6,7,9} MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = {1,2,4,5,6,7,10} = E b

$ A

b a

C a

B

$ $ b

D

a © Harry H. Porter, 2005

36

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process D = {1,2,4,5,6,7,9} MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = {1,2,4,5,6,7,10} = E b

$ A

$

C

b

a

B

a

a

$

D

b

$

E

b

a © Harry H. Porter, 2005

37

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process E = {1,2,4,5,6,7,10}

Process D = {1,2,4,5,6,7,9} MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = {1,2,4,5,6,7,10} = E

MoveDFA(E,a) = MoveDFA(E,b) =

b

$ A

b a

C a

B

$ a

$ b

D

$ b

E

a © Harry H. Porter, 2005

38

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process E = {1,2,4,5,6,7,10}

Process D = {1,2,4,5,6,7,9}

MoveDFA(E,a) = {1,2,3,4,6,7,8} = B MoveDFA(E,b) =

MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = {1,2,4,5,6,7,10} = E b

$ A

$

C

b

a

B

a

a

$

D

b

$

E

b

a © Harry H. Porter, 2005

39

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3 5

%= {a,b}

#

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process E = {1,2,4,5,6,7,10}

Process D = {1,2,4,5,6,7,9} MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = {1,2,4,5,6,7,10} = E

MoveDFA(E,a) = {1,2,3,4,6,7,8} = B MoveDFA(E,b) = {1,2,4,5,6,7} = C

b

$ A

b a

C a

B

$ a

$ b

D

$ b

E

a © Harry H. Porter, 2005

40

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3

%= {a,b}

#

5

6

#

7

#

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process E = {1,2,4,5,6,7,10}

Process D = {1,2,4,5,6,7,9}

MoveDFA(E,a) = {1,2,3,4,6,7,8} = B MoveDFA(E,b) = {1,2,4,5,6,7} = C

MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = {1,2,4,5,6,7,10} = E b

$ A

C

b

a

B

a

b

$ a a

$

D

b

$

E

b

$

a © Harry H. Porter, 2005

41

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3

%= {a,b}

#

5

6 #

#

7

a

8

b

9

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process E = {1,2,4,5,6,7,10}

Process D = {1,2,4,5,6,7,9} MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = {1,2,4,5,6,7,10} = E b

$ A

b a

C a

B

Final States in DFA? ...which state(s) contain 10?

b

$

MoveDFA(E,a) = {1,2,3,4,6,7,8} = B MoveDFA(E,b) = {1,2,4,5,6,7} = C

a a

$ b

D

$ b

E

$

a © Harry H. Porter, 2005

42

Lexical Analysis - Part 3

Example #

0

2

#

1

4

#

Process C = {1,2,4,5,6,7}

a

b

#

3

%= {a,b}

#

5

6

#

7

#

a

8

9

b

b

10

#

MoveDFA(C,a) = {1,2,3,4,6,7,8} = B MoveDFA(C,b) = {1,2,4,5,6,7} = C Process E = {1,2,4,5,6,7,10}

Process D = {1,2,4,5,6,7,9} MoveDFA(D,a) = {1,2,3,4,6,7,8} = B MoveDFA(D,b) = {1,2,4,5,6,7,10} = E b

Final Result:

$ A

C

b

a

a

B

Final States in DFA? ...which state(s) contain 10?

b

$

MoveDFA(E,a) = {1,2,3,4,6,7,8} = B MoveDFA(E,b) = {1,2,4,5,6,7} = C

a a

$ b

D

$ b

E

$

a © Harry H. Porter, 2005

43

Lexical Analysis - Part 3

Algorithm: Convert NFA to DFA SDFA = {} Add #-Closure(s0) to SDFA as the start state Set the only state in SDFA to “unmarked” while SDFA contains an unmarked state do Let T be that unmarked state A set of NFA states Mark T for each a in % do Everywhere you could S = #-Closure(MoveNFA(T,a)) possibly get to on an a if S is not in SDFA already then Add S to SDFA (as an “unmarked” state) endIf Set MoveDFA(T,a) to S i.e, add an edge to the DFA... a

{t1,t2,...}

endFor T endWhile for each S in SDFA do if any s&S is a final state in the NFA then Mark S an a final state in the DFA endIf endFor © Harry H. Porter, 2005

{s1,s2,...}

S

44

Lexical Analysis - Part 3

Resulting DFA for (a|b)*abb b b

C b

A

a

a

a

B

a

D

b

E

b

a

Is it minimal?

© Harry H. Porter, 2005

45

Lexical Analysis - Part 3

Resulting DFA for (a|b)*abb b b

C b

A

a

a

a

B

a

D

b

E

b

a

Is it minimal?

A

© Harry H. Porter, 2005

a

B

b

D

b

E

46

Lexical Analysis - Part 3

Resulting DFA for (a|b)*abb b b

C b

A

a

a

a

B

a

D

b

E

b

a

Is it minimal?

A

B

a

D

b

E

b

© Harry H. Porter, 2005

47

Lexical Analysis - Part 3

Resulting DFA for (a|b)*abb b b

C b

A

a

a

a

B

a

D

b

E

b

a b

Is it minimal?

A

a

B

b

D

b

E

b

© Harry H. Porter, 2005

48

Lexical Analysis - Part 3

Resulting DFA for (a|b)*abb b b

C b

A

a

a

a

B

a

D

b

E

b

a b

Is it minimal?

a a

A

B

a

b

D

b

E

b

a

© Harry H. Porter, 2005

49

Lexical Analysis - Part 3

Resulting DFA for (a|b)*abb b b

C b

A

a

a

a

B

a

D

b

E

b

a b

Is it minimal?

Every Regular Set is recognized by a minimal DFA!

a a

A b

© Harry H. Porter, 2005

a

B

b

D

b

E

a

50

Lexical Analysis - Part 3

Resulting DFA for (a|b)*abb b b

C b

A

a

a

a

B

a

D

b

E

b

a b

Is it minimal?

Every Regular Set is recognized by a minimal DFA!

a a

A b

© Harry H. Porter, 2005

a

B a

b

D

b

E And it is unique, up to renaming of states

51