Grammatical question, problem with FIRST

Consider the following grammar:

A → BC
B → Ba | epsilon
C → bD | epsilon
D → …

The problem here is that the rule Bcan also output epsilonleft recursive.

To find FIRST(A), I am looking FIRST(B).
But I'm stuck on FIRST(B)because it is left-recursive.

So what is it FIRST(B)? And FIRST(A)?
My version:

FIRST(B) → {a, epsilon}
FIRST(A) → {a, b, epsilon}

Is it correct?

+3
source share
1 answer

Yes, you are fine. Left recursion does not affect FIRST, because when it Bamatches B, Bc Bamust start with something that it can start with B, because it's a B, after all. :)

Instead, you can set left recursion first instead.

+2
source

Source: https://habr.com/ru/post/1777520/


All Articles