3. What is left recursion?
Eliminating left Recursion...
Example of Eliminating Left Recursion
Conclusion
Reference
Code part
Slide 3
OVERVIEW
4. In the formal language theory of computer science , left recursion is a
special case of recursion where a string is recognized as part of a language
by the fact that it decomposes into a string from that same language (on the
left) and a suffix (on the right). For instance 1+2+3 can be recognized as a
sum because it can be broken into 1+2, also a sum, and +3, a suitable
suffix.
Slide 4
6. LEFT RECURSION
The production is left-recursive if the leftmost symbol on the
right side is the same as the non terminal on the left side. For
example,
expr → expr + term.
If one were to code this production in a recursive-descent
parser, the parser would go in an infinite loop.
Slide 6
7. We can eliminate the left-recursion by introducing new nonterminals and
new productions rules.
For example, the left-recursive grammar is:
E → E + T | T
E → T * F | F
F → (E) | id.
We can redefine E and T without left-recursion as
E → TE`
E`→ + TE` | E
T → FT`
T → * FT` | E
F → (E) | id
Getting rid of such immediate left recursion is not enough. One must get rid of
indirect left recursion too, where two or more nonterminals are mutually left-
recursive
Slide 7