0

Is there any formal algorithm or steps to rewrite a grammar that has no left-recursion and shows right precedence. Such as that simple algorithm for eliminating left recursion described in Wikipedia

For example, given the following algorithm:

1 <goal> ::= <expr>$
2 <expr> ::= <expr><op><expr>
3           | num
4           | id
5 <op>   ::= +
6           |-
7           |*
8           |/

The desired output should be:

1. <expr> ::= <term><expr'>
2. <expr'> ::= +<term><expr'>
3.           | epsilon
4.           | -<term><expr'>
5. <term>  ::= <factor><term'>
6. <term'> ::= *<factor><term'>
7.           | epsilon
8.           | /<factor><term'>
objmagic
  • 1,028
  • 1
  • 9
  • 18

0 Answers0