Thompson’s algorithm

Thompson’s algorithm . Algorithm that allows from a regular expression to obtain a non-deterministic finite automaton with empty transitions (AFND-V) equivalent.

Table of Contents

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:

  1. The initial state Q0: is placed .
  2. If the expression supports the empty string, Q0is indicated as a final state:
  3. Each xterminal symbol is represented by a transition .
  4. Disjunction (|). Let the expression 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 1 and 2
  5. Concatenation (.). Let the expression 1 .e 2 or more simply 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 1 and 2 . After concatenation, normally T (e 1 ) loses its final states to leave only those of T (e 2 ) .
  6. Closing (*). Let the expression 1 * be the equivalent AFND-V take the form: where T (e 1 ) is the AFND-V resulting from the expressions 1 .
  7. 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 21 = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 and 221 = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 until they are fully reduced.

 

by Abdullah Sam
I’m a teacher, researcher and writer. I write about study subjects to improve the learning of college and university students. I write top Quality study notes Mostly, Tech, Games, Education, And Solutions/Tips and Tricks. I am a person who helps students to acquire knowledge, competence or virtue.

Leave a Comment