0
$\begingroup$

A common left recursion:

A -> Aa | B

can be solve by transforming it into:

A  -> BA'
A' -> aA' | E

However, I face another similar yet different left recursion when I'm writing my compiler:

A -> (A|B) a

So, my question is, how to solve such left recursion?

$\endgroup$
1
$\begingroup$

Rewriting (A|B) a as Aa | Ba allows you to apply the solution you already have (with Ba instead of B).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.