Reputation: 73
Can you eliminate ambiguity by left factoring?
For example, the dangling else.
Or is left factoring only eliminating left recursion?
Thanks.
Upvotes: 0
Views: 1446
Reputation: 254
In the case of the dangling else, ambiguity is not eliminated by left factoring. You will still have two parse trees for nested if statements.
Upvotes: 1
Reputation: 28829
This is exactly what left factoring usually refers to.
Example:
Before
G = "IF" cond "THEN" statements
| "IF" cond "THEN" statements "ELSE" statements
...
After
G = "IF" condition "THEN" statements G'
G' = "ELSE" statements
| Εpsilon
...
Upvotes: 1