Sub topic 8
From Regular Expression to Automaton
Prerequisites and goal
Assume you know deterministic finite automata (DFAs), nondeterministic finite automata (NFAs), epsilon transitions, and the meaning of regular-expression operators. This chapter shows how to convert a regular expression into an equivalent epsilon-NFA.
An epsilon transition consumes no input symbol. It lets the automaton choose between paths or move between fragments. The construction is useful because it gives a systematic proof that every regular expression describes a regular language.
Basic construction rules
Use one automaton fragment with a single entry state and a single exit state for each expression. Mark the entry and exit states clearly. The exit state becomes accepting only after the complete expression has been processed.
| Expression | Construction | Column |
|---|---|---|
| Symbol `a` | Entry --`a`--> exit | |
| Empty string ε | Entry --`ε`--> exit | |
| Union `R | S` | A new entry branches by ε to the fragments for `R` and `S`; both exits go by ε to a new exit |
| Concatenation `RS` | Connect the exit of `R` to the entry of `S` with ε | |
| Kleene star `R*` | A new entry can skip `R` or enter it; the fragment can return to itself, and its exit can reach a new exit |
The construction is often called Thompson's construction. It creates at most a small constant number of states for each operator and symbol. The resulting machine may have epsilon transitions and may be nondeterministic.
Worked construction: `(a|b)*abb`
Start with the innermost expression a|b. Build separate one-symbol fragments for a and b, then join them with a new entry and exit. Apply the star rule to this whole fragment. Finally, concatenate the fragments for a, b, and b.
The complete machine accepts exactly the strings that end with abb, because the starred part can consume any sequence of a and b symbols before the final three symbols.
This diagram suppresses the internal epsilon states used by a literal Thompson construction. In a formal solution, draw the separate branch for a and b, the epsilon links into and out of the star fragment, and the epsilon links between concatenated fragments.
Checking the result
To process an input string, maintain the set of states reachable through epsilon transitions. After reading a symbol, follow matching transitions and then compute epsilon-closure again. The string is accepted if the final reachable set contains the accepting state.
For GATE problems, check these points:
- Union creates a choice between complete submachines.
- Concatenation preserves order.
- Star permits zero or more repetitions, including zero.
- The final accepting state belongs to the whole expression, not to every fragment.
- Epsilon transitions do not increase the input position.
After constructing the epsilon-NFA, you can remove epsilon transitions or apply subset construction to obtain an equivalent DFA.
Exercise
What structural operation should be applied first when converting (a|b)*a using Thompson's construction?
Show answer
Construct the fragments for a and b, join them using the union rule, apply the star rule to that combined fragment, and then concatenate the final a fragment.