Search code examples
regexfinite-automataregular-language

How would I convert regular expression to finite automata?


How would I change the following regular expression to finite automata?

(abUb)(bUaaa)b*b((a*b)*Ub)*

note: U means union in this case


Solution

  • There are five top-level concatenated components of this regex. According to the algorithm recoverable from a part of Kleene's theorem, you can make NFA-Lambdas for these, then form the concatenation by connecting final states of one to initial states of the next.

    When you see a union, that means you make two machines and combine them by making a new start state with two lambda transitions.

    Kleene closure is a little more involved, but basically make the machine for the thing being repeated, then transform it by adding a new accepting start state and a loop to it from the old final states.

    The base case is the machine for a single letter, which is two states, initial and final, with the appropriately labelled transition.

    Work recursively from the simplest machines (innermost subexpressions) up to the whole thing, combining as necessary. Simplify the result as much as you like, possibly converting to a minimal DFA.