James Edwins
James Edwins

Reputation: 73

Eliminating ambiguity by left factoring

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

Answers (2)

CSharpFiasco
CSharpFiasco

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

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

Related Questions