Thompson’s algorithm . Algorithm that allows from a regular expression to obtain a non-deterministic finite automaton with empty transitions (AFND-V) equivalent.
Summary
[ hide ]
- 1 Definition
- 2 Example
- 3 See also
- 4 Sources
Definition
Let be a regular expression E, it is traversed according to the order of operational precedence (*,., |) And the groupers to obtain an AFND-V defined by its state diagram according to the steps:
- The initial state Q0: is placed .
- If the expression supports the empty string, Q0is indicated as a final state:
- Each xterminal symbol is represented by a transition .
- Disjunction (|). Let the expression e 1 | e 2 be the equivalent AFND-V take the form: where T (e 1 ) and T (e 2 ) are the AFND-V resulting from the expressions e 1 and e 2
- Concatenation (.). Let the expression e 1 .e 2 or more simply e 1 e 2 the equivalent AFND-V take the form: where T (e 1 ) and T (e 2 ) are the AFND-V resulting from the expressions e 1 and e 2 . After concatenation, normally T (e 1 ) loses its final states to leave only those of T (e 2 ) .
- Closing (*). Let the expression e 1 * be the equivalent AFND-V take the form: where T (e 1 ) is the AFND-V resulting from the expressions e 1 .
- It continues until there are no regular expressions left to convert.
Example
Get a finite automaton equivalent to the regular expression that defines unsigned integers in the Python programming language .
Natural constants or literals in Python are defined by the regular expression:
- 0 | ((1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9) (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9) *)
The first case is a disjunction that can be outlined as:
Then follows the concatenation ((1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9) (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9) *) whose representation remains :
It continues momentarily altering the original order, for didactic purposes, the closure and 22 = (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9) * :
Then, we continue applying the algorithm to the expressions e 21 = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 and e 221 = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 until they are fully reduced.