In: Computer Science
A → A a b | B d
B → b d | b e
(upper cases are nonterminals; lower cases are terminals)
Remove the left recursion in the grammar?
Perform left factoring if there exists some common prefix among choices?
1. To remove left recursion,
A
Aa | b (Left recursive grammar)
After removing left recursion,
Apply this on above grammar,
here A
Aab has left recusrion, we can write it as a
Now no any production rule has left recursion.
The grammar will be,
2. In given grammar there exists left factoring as we have a production rule,
Here, parser can't decide which production rule must be chosen to parse string in hand.
process to remove left factoring,
will change to
Apply this in above grammar,
After removing left factoring,
After removing left factoring,
Combining all production rules,we get
the grammar withoot left ecursion and left factoring