LR(1)项的讨论:含义?

发布于 2025-01-03 05:21:09 字数 138 浏览 1 评论 0原文

什么是规范的 LR(1) 项!我读过龙书,它让我困惑,(delta,gamma,toh,...)

有人可以帮助我解决这个问题吗?

这个英文是什么意思? [A-> alpha.Bbeta , a]

非常感谢..

What is the canonical LR(1) items ! I have read the Dragon Book, It confuses Me , (delta,gamma,toh,...)

Can Someone help me with this issue ?

What is this meaning in English? [A - > alpha.Bbeta , a]

Thanks a lot..

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

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

发布评论

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

评论(2

淤浪 2025-01-10 05:21:09

<代码>[A->阿尔法。 B beta , a] 基本上意味着“假设规则 A 正在扩展,到目前为止我们已经看到了 alpha。然后我们期望看到 B beta。我们还知道,在 A 之后,我们将看到一个 a

因此,在 CLR(1) 中,您的状态由其中一些组成。项目。然后您有很多选择:

  • 如果前瞻 (gamma) 是 first(B) 的成员,并假设您有诸如 B->gamma C 的规则>,然后你可以“转移”并进入包含 [B ->; 的状态伽玛。 C,测试版]。如您所见,. 已移动超过 gamma(因为 gamma 已匹配,并且 B 的后续内容为beta 因为这是规则 A -> alpha B betaB 之后的内容,
  • 如果前瞻是 a<。 /code> 并假设 B beta 可以生成lambda (空字符串)(这里,假设 beta 是一个可以生成 lambda 的非终结符),然后,您可以“减少”并进入包含诸如以下规则的状态。 C -> Something A . a Something_else,follow] 在这种情况下,您已决定 alphaB。 beta 堆栈上的可以归为一A

这是我可以解释的最简单的方式。

[A -> alpha . B beta , a] basically means "assuming rule A was being expanded, so far we have seen alpha. We then expect to see B beta. We also know that after A, we are going to see an a"

So, in CLR(1), you have states consisting of some of these items. You then have many options:

  • If the look-ahead (gamma) is a member of first(B), and assuming you have a rule such as B->gamma C, then you can "shift" and go to a state containing [B -> gamma . C, beta]. As you can see, the . has moved passed gamma (because gamma is matched and the follow of B is beta because that's what came after B in the rule A -> alpha B beta.
  • If the look-ahead is a and assuming B beta could generate lambda (empty string) (here, assume beta is a nonterminal that can generate lambda). Then, you can "reduce" and go to a state that contains rules such as C -> something A . a something_else, follow]. In this case, you have decided that the alpha, B and beta on the stack can be grouped into one A.

That was the simplest way I could explain this.

我不吻晚风 2025-01-10 05:21:09

IIRC,这是一个“项”,即某种句子形式解析的潜在状态。

这意味着:

[A - > alpha.Bbeta , a]

当尝试解析可被视为非终结符 A 的(目标语言的子字符串)时,是否已看到 alpha,并且 ( ".") 预计接下来是 Bbeta,并且如果看到非终结符的元素,则如果下一个标记是 a<,则它是有效的 A /强>。

(我认为你把Bbeta抄错了,书里可能是beta)。

IIRC, this is an "item", that is, the potential state of some sentential form parse.

What this means:

[A - > alpha.Bbeta , a]

is that when attempting to parse a (substring of the target language) which can be considerat as the nonterminal A, is the alpha has been seen, and (".") that Bbeta is expected next, and that if the elements of the nonterminal are seen, it is a valid A if the next token is a.

(I think you transcribed Bbeta wrong, it was probably beta in the book).

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