如何确定该语法中 E 的第一组?

发布于 2024-08-09 10:07:17 字数 129 浏览 2 评论 0原文

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

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

任何人都可以给我一些指导吗?

I wonder how to determine the FIRST set of E with grammar:

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

Can anyone give me some direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

dawn曙光 2024-08-16 10:07:17

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

这看起来很简单...

Well, assuming that you're starting with E, then either the first terminal is x via the EXYE production (since X always produces x) or it is e via the E→e production. So First(E) = {x,e}.

That seems pretty straightforward...

何时共饮酒 2024-08-16 10:07:17

对待形式A的规则-> ...x... | ...你....
两条规则 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 包含以下标记:
是第一个(F)。

这没有考虑空生产。

Treat rules of the form A -> ...x... | ...y ....
as two rules A -> ...x... and B -> ...y...

Form a set S initially containing rules of form E-> ....

then

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

WHen the loop terminates, F contains the tokens which
are the First(F).

This does not take into account empty productions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文