I'm trying to write a compiler for C (simpler grammar though).
There is something that I've been stuck on for a while. If I understated correctly, all binary operations are left associative. So if we have we "x+y+z", x+y occurs first and then followed by plus z.
However, doesn't enforcing left associativity causes infinite left recursion?
So far all solutions that I've checked are either left associative or don't have left recursion, but not both. Is it possible to have a grammar that have both of these properties. Is it even possible?
Example:
Left Associative:
Expr = Term | Expr + Term
Term = Element | Term ∗ Element
Element = x|y|z|(Expr)
Left Recursion Eliminated:
Expr = Term ExprTail
ExprTail = epsilon | + Term ExprTail
Term = Element TermTail
TermTail = epsilon | * Element TermTail
Element = x|y|z|(Expr)
Any ideas?