Can you eliminate ambiguity by left factoring?
For example, the dangling else.
Or is left factoring only eliminating left recursion?
Thanks.
Can you eliminate ambiguity by left factoring?
For example, the dangling else.
Or is left factoring only eliminating left recursion?
Thanks.
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
...
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.