Parsing 跟随集自上而下解析

Parsing 跟随集自上而下解析,parsing,compiler-construction,ll,Parsing,Compiler Construction,Ll,我对以下规则有一个问题: L -> CL' L' -> epsilon | ; L C -> id:=G |if GC |begin L end 我已经计算出Follow(L)在Follow(L')中。另外,Follow(L')位于Follow(L)中,因此它们都将包含:{end,$}。但是,由于L'是可空的,Follow(L)是否也包含Follow(C) 我已经计算出Follow(C)=First(L')和Follow(C)子集Foll

我对以下规则有一个问题:

L -> CL'
L' -> epsilon
       | ; L
C -> id:=G
      |if GC
      |begin L end
我已经计算出
Follow(L)
Follow(L')
中。另外,
Follow(L')
位于
Follow(L)
中,因此它们都将包含:
{end,$}
。但是,由于
L'
是可空的,
Follow(L)
是否也包含
Follow(C)

我已经计算出
Follow(C)
=
First(L')
Follow(C)子集Follow(L)={;$end}

在回答中,
Follow(L)
Follow(L')
只包含
{end,$}
,但不应该包含
以及从
后面的(C)
作为
L'
可以为空

谢谢

但是,由于
L'
是可空的,
Follow(L)
是否也包含
Follow(C)

恰恰相反<代码>跟随(C)
将包含
跟随(L)
。想想下面这句话:

...Lx...
其中X是某个终端,因此位于
Follow(L)
中。这可以扩展到:

...CL'x...
并进一步:

...Cx...
所以L后面的,也可以跟C。相反的,不一定是真的


要计算如下值,请考虑一个图,其中节点为(NT,n),这意味着非终端
NT
,令牌长度如下(在LL(1)中,
n
为1或0)。您的图表如下所示:

     _______
   |/_      \
(L, 1)----->(L', 1)         _(C, 1)
 |  \__________|____________/| |
 |             |               |
 |             |               |
 |   _______   |               |
 V |/_      \  V               V
(L, 0)----->(L', 0)         _(C, 0)
    \_______________________/|

其中
(X,n)-->(Y,m)
表示
X
的长度
n
的跟数,取决于
Y
的长度
m
的跟数(当然,
m‘告诉我詹姆斯:你睡觉的时候枕头下还放着龙书吗?’+1为了清楚,细节。@user1666959,已经度过了很多个夏夜。@user1666959而且,我也找不到那句话,它从哪里来的?“明天永不消逝”,帕里斯·卡弗(特里·哈彻)在聚会上告诉Bond,稍微改了一下措辞,以确认您对编译器构造的了解可能与Bond对Walther PPK的了解一样多。@user1666959,谢谢您的补充和信息;)
Y -> ... X REST
S -> A a b c
A -> B C d
C -> epsilon | e | f g h i
A -> B C d
"C d" with length 0 (complete):
"C d" with length 1 (complete):
    d
"C d" with length 2 (complete):
    e d
"C d" with length 3 (complete or not):
    f g h
follow(A, 0):
    epsilon
follow(A, 1):
    a
follow(A, 2):
    a b
follow(A, 3):
    a b c

"C d" with length 0 (complete) concat follow(A, 3):
"C d" with length 1 (complete) concat follow(A, 2):
    d a b
"C d" with length 2 (complete) concat follow(A, 1):
    e d a
"C d" with length 3 (complete or not) concat follow(A, 0) (Note: follow(X, 0) is always epsilon):
    f g h