You can also check out this wiki page for more info on left recursion :
http://en.wikipedia.org/wi
Main Topics
Browse All TopicsI've been working on a project that would involve parsing arithmetic-like expressions.
I found this page:
http://compilers.iecc.com/
And I mostly understand it, but I could really use some more info about what the phrase "eliminate left-recursion" means there, and some detail on how that gets from the first to the second grammar listed. Also, what are the epsilons, where do they come from, why?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You can also check out this wiki page for more info on left recursion :
http://en.wikipedia.org/wi
>> You mentioned the second rule uses left recursion. Does the first, also?
Yes ... I just picked one of them as example - the other can be dealt with in exactly the same way.
>> If so, would it still use left recursion if it was instead:
>>
>> E -> T+E | T-E | T
No, that's right recursive.
Note that there is an extra problem with changing rules like this : the associativity can change.
Take for example the string "T + T + T".
parsing it with the original rule :
E -> E+T | E-T | T
we get :
T + T + T
E + T
(E + T) + T
(T + T) + T
while with your rule :
E -> T+E | T-E | T
we get :
T + T + T
T + E
T + (T + E)
T + (T + T)
and with the "fixed" rule from the link you posted :
E -> TE'
E' -> +TE' | -TE' | \epsilon
we get :
T + T + T
TE'
T + TE'
T + (T + TE')
T + (T + T)
Note that the associativity changed from left ((T + T) + T) to right (T + (T + T)). In the case of addition, this is not a problem, but it can be a problem with other operations, like subtraction, ie. : ((T - T) - T) is not the same as (T - (T - T)).
Business Accounts
Answer for Membership
by: Infinity08Posted on 2007-06-07 at 08:12:21ID: 19234274
This grammar :
E -> E+T | E-T | T
T -> T*F | T/F | F
F -> +F | -F | number | (E)
uses left recursion. Let's look at the second rule specifically :
T -> T*F | T/F | F
This allows strings like :
F
F*F
F/F
F*F*F
F/F*F
etc.
or any other combinations of multiplying and dividing factors (F).
The T is on the left side of the rule results :
T*F
T/F
which is why it's called left recursion ... ie. new content is added on the left when constructing the string :
T
T*F <--- because of first option T -> T*F
T/F*F <--- because of second option T -> T/F
F/F*F <--- because of third option T -> F
This poses a problem for recursive descent parsers, because they can't parse something like that. An LALR parser by contrast prefers left recursion.
So, if we make use of a recursive descent parser, we'll have to eliminate the left recursion, and form a new grammar that can be used by a recursive descent parser.
One option is to do this (from the page you linked to) :
T -> FT'
T' -> *FT' | /FT' | \epsilon
ie. now right recursion is used (the T is on the right side of the options), and since \epsilon stands for the empty string, these rules describe the same set of possible strings. For example, we can form :
T
FT' <--- because of the first rule T -> FT'
F/FT' <--- because of second option T' -> /FT'
F/F*FT' <--- because of first option T' -> *FT'
F/F*F <--- because of third option T' -> \epsilon