Theoretical Aspects of Lexical Analysis/Exercise 3

From Wiki**3

< Theoretical Aspects of Lexical Analysis

Problem

Use Thompson's algorithm to build the NFA for the following regular expression. Build the corresponding DFA and minimize it.

  • ((ε|a)b)*

Solution

The non-deterministic finite automaton (NFA), built by applying Thompson's algorithm to the regular expression ((ε|a)b)* is the following:

nfa 0 0 start->0 8 8 0->8 1 1 0->1 2 2 1->2 4 4 1->4 3 3 2->3 5 5 4->5 a 6 6 3->6 7 7 6->7 b 5->6 7->8 7->1

Applying the determination algorithm to the above NFA, the following determination table is obtained:

In α∈Σ move(In, α) ε-closure(move(In, α)) In+1 = ε-closure(move(In, α))
- - 0 0, 1, 2, 3, 4, 6, 8 0
0 a 5 5, 6 1
0 b 7 1, 2, 3, 4, 6, 7, 8 2
1 a - - -
1 b 7 1, 2, 3, 4, 6, 7, 8 2
2 a 5 5, 6 1
2 b 7 1, 2, 3, 4, 6, 7, 8 2
Graphically, the DFA is represented as follows:
dfa 0 0 start->0 2 2 0->2 b 1 1 0->1 a 2->2 b 2->1 a 1->2 b

Given the minimization tree to the right, the final minimal DFA is:

dfamin 02 02 start->02 02->02 b 1 1 02->1 a 1->02 b
The minimization tree is as follows.
mintree {0, 1, 2} {0, 1, 2} {1} {1} {0, 1, 2}->{1} NF {0, 2} {0, 2} {0, 1, 2}->{0, 2}  F {0,2} {0,2} {0, 2}->{0,2}  a,b