
The general algorithm to remove the left recursion follows. Several improvements to this method have been made.
For each rule of the form
A
A a1 | A a2 | ... | A a m | β 1 |β 2 | .. |β n
Where:
. A is a left-recursive non-terminal.
. a is a sequence of non-terminals and terminals that is not null ( a≠ε ).
. ß is a sequence of non-terminals and terminals that does not start with A .
Replace the A-production by the production:
A
β 1 A' | β2 A' | ...| βn A'
And create a new non-terminal
A'
a1 A' | a2 A' |...| am A' | ε
This newly created symbol is often called the "tail", or the "rest".