0

Can you eliminate ambiguity by left factoring?

For example, the dangling else.

Or is left factoring only eliminating left recursion?

Thanks.

James Edwins
  • 73
  • 1
  • 5

2 Answers2

1

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
...
1

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.

CSharpFiasco
  • 204
  • 3
  • 8