How to convert regular grammar to regular expression?

Is there an algorithm or tool to convert regular grammar to regular expression?

+6
source share
2 answers

Dalibocai answer:

My goal is to convert regular grammar to DFA. Finally, I found a great tool: JFLAP .

+1
source

The algorithm is pretty simple if you can compute an automaton from your regular expression. As soon as you have your own machine. For example, for (aa*b|c) automaton will be (arrows go to the right):

  a / \ a \ / b -> 0 ---> 1 ---> 2 -> \___________/ c 

Then just β€œlist” your transitions as rules. Below, we consider that 0, 1, and 2 are nonterminal symbols, and, of course, a, b, and c are tokens.

 0: a1 | c2 1: a1 | b2 2: epsilon 

or if you do not want empty right sides.

 0: a1 | c 1: a1 | b 

And, of course, a route in the other direction provides one means of converting a regular grammar into an automaton, hence a rational expression.

+1
source

Source: https://habr.com/ru/post/906215/


All Articles