Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting regular expression to finite state machine

Would you have a hint at algorithm to convert any regular expression to a Finite State Machine (FSM). For instance, an algorithm parsing a regexp and adding states to the FSM appropriately? Any reference or deeper idea?

I am writting this with Python

like image 650
kiriloff Avatar asked Jul 11 '12 06:07

kiriloff


People also ask

What is the regular expression for finite state machine?

Regular expressions describe patterns which can be recognized by finite state machines (FSM). It is possible to algorithmically construct a FSM that corresponds to a given regular expression. A FSM can be described by a transition table (program), which can be represented by a string.

What method that is popularly used in converting Re to Fa?

To convert the RE to FA, the method that is popularly used is known as the Subset method. This method is used to get FA from the given regular expression. Step 1: Make a transition diagram for a given regular expression, using NFA with ε moves. Step 2: Then, Convert this NFA with ε to NFA without ε.

How to convert regular expression to finite automata?

How to convert Regular expression to Finite Automata? To convert the regular expression (RE) to Finite Automata (FA), we can use the Subset method. Subset method is used to obtain FA from the given RE. Step 1 − Construct a Transition diagram for a given RE by using Non-deterministic finite automata (NFA) with ε moves.

How to convert FA to regular expression?

There are two methods to convert FA to regular expression –. 1. State Elimination Method –. Step 1 –. If the start state is an accepting state or has transitions in, add a new non-accepting start state and add an €-transition between the new start state and the former start state. Step 2 –.

How to convert re to FA in Excel?

To convert the RE to FA, the method that is popularly used is known as the Subset method. This method is used to get FA from the given regular expression. Step 1: Make a transition diagram for a given regular expression, using NFA with ε moves. Step 2: Then, Convert this NFA with ε to NFA without ε.

What are the prerequisites for using regular expressions?

Prerequisite – Introduction of FA, Regular expressions, grammar and language, Designing FA from Regular Expression 1. State Elimination Method – If the start state is an accepting state or has transitions in, add a new non-accepting start state and add an €-transition between the new start state and the former start state.


1 Answers

Use Michael Sipser's Introduction to the Theory of Computation. Chapter 1 gives detailed algorithms for converting a regular expression to a deterministic or non-deterministic finite-state automaton (DFA or NFA), in the context of proving their equivalence (a DFA, an NFA and a regular expression can match exactly the same classes of strings).

The general idea is: You convert a regular expression to an NFA, which can be done quite straightforwardly (* is a loop, | and character ranges are branch points). You then convert the NFA into a (much larger) DFA, which involves creating one DFA state for each set of alternative NFA states. The DFA has at most as many states as the powerset of the set of NFA states (e.g., an NFA with 3 states can get transformed to a DFA with at most 2^3 = 8 states), and can recognize any target string without backtracking. Read the book for the details.

like image 76
alexis Avatar answered Sep 28 '22 16:09

alexis