开发者

Grammar question, problem with FIRST

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜