1

How can I convert a regular expression such as:

((e|£|\$)([1-9][0-9]*|0)(,|\$|\.){1}([0-9][0-9]))|(([1-9][0-9]*|0),[0-9][0-9](EUR))|([1-9][0-9]*|0)\$[0-9]{2}

to a finite automata like this:

finite automata like this

Barmar
  • 596,455
  • 48
  • 393
  • 495
  • Are you asking how to create the diagram, or compile it into a state table? – Barmar Mar 03 '20 at 17:26
  • @Barmar I want the diagram, but if there is any way to create a state table and then get the diagram (using something like graphviz) I can take it. –  Mar 03 '20 at 17:29

2 Answers2

2

Try this online tool https://regexper.com/ which will automatically generate diagram

enter image description here

Kamil Kiełczewski
  • 53,729
  • 20
  • 259
  • 241
  • 1
    I'm sorry, although it is very useful, I wan't that specific diagram type. –  Mar 03 '20 at 17:30
  • 2
    @RafaelMoreira: This diagram is almost the diagram you need. All you need to do is add explicit transitions in the place of the `one of`s and add states for every branch. (Then run the NFA-to-DFA algorithm on the result if you need a DFA instead of an NFA.) – Welbog Mar 04 '20 at 14:10
1

I won't go through the details but the process might look like this:

  1. Rewrite your regex as a fully-parenthesized formal regular expression. If your regex has no equivalent fully parenthesized formal regular expression, stop; there is no finite automaton.

  2. Use the standard constructive algorithm for proving finite automata are as powerful as (formal) regular expressions to construct a nondeterministic finite automaton which accepts the language described by the (formal) regular expression obtained in step 1.

  3. Optional: determinize the nondeterministic finite automaton obtained in step 2 using e.g. the subset/powerset constructive algorithm used to show deterministic finite automata are as powerful as nondeterministic ones.

  4. Optional: minimize the deterministic finite automaton obtained in step 3 using some standard DFA minimization algorithm.

Patrick87
  • 25,592
  • 3
  • 33
  • 69