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.
source share