Consider following grammar:
A → BC
B → Ba | epsilon
C → bD | epsilon
D → …
…
The problem here is that rule B can derive epsilon and left-recursive as well.
In order to find FIRST(A) I am searching FIRST(B).
But I stuck on FIRST(B), because it is left-recursive.
So what is FIRST(B)? And FIRST(A)?
My version is:
FIRST(B) → {a, epsilon}
FIRST(A) → {a, b, epsilon}
Is that correct?
Yes, you have it right. A left-recursion does not contribute to FIRST, because when Ba is matched for B, the B in Ba must start with something that B can start with - because it's a B, after all. :)
You could also instead factor out the left-recursion first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With