1

我想知道如何FIRST用语法确定 E 的集合:

E -> XYE | e
X -> x
Y -> y

谁能给我一些指导?

4

2 回答 2

3

好吧,假设您从E开始,那么第一个终端是 x 通过EXYE产生式(因为X总是产生 x),或者它是 e 通过E →e 产生式。所以首先(E)= {x,e}。

这似乎很简单......

于 2009-11-02T02:17:25.687 回答
0

处理 A -> ...x... 形式的规则 | ...y .... 作为两个规则 A -> ...x... 和 B -> ...y...

形成一个集合 S,最初包含形式 E-> ... 的规则。

然后

Set a set P to empty.
Set a set F to empty.
Repeat until S is empty 
  Choose element of S, and call it R
  If R is in P, remove R from S
  Elsif R is of the form  A -> b ... 
    then { add b to F,
           add R to P,
           remove R from S}
  Else (R is the form A -> B ...)
     then  { place all rules of form B -> ... into S
             remove R from S}
End

当循环终止时,F 包含作为 First(F) 的标记。

这不考虑空产品。

于 2009-11-02T02:26:01.527 回答