CFG 算术优先级/歧义

发布于 2024-10-15 06:09:37 字数 299 浏览 3 评论 0原文

自从我与 CFG 合作以来已经有一段时间了。无论如何,我有一个特定的语法可以正确地完成所有操作,但最后(我排除了其他标准数学操作)。

S ::= S+T | ST | T

T ::= 非终结符 |身份证 | -S | (S)

根据我所拥有的一切..我知道-S 应该是-T。但另外......这对优先级有什么影响。是不是很暧昧?从数学上讲,我可以显然它是不正确的..但这不应该在歧义问题上产生影响。

如果它是 -T,那么它与 (S) 具有相同的优先级吗?

真正尝试理解这是如何发生的并循环回到开始状态。

Been a while since I've worked w/ CFG. Anyways, I have a particular grammar that goes through all the operations properly, but at the end (I excluded other standard mathematic operations).

S ::= S+T | S-T | T

T ::= nonterminal | ID | -S | (S)

per everything I have.. I know that -S should be -T. But additionally.. what does that do to the precedence. Is it ambiguous? Mathematically I can it obviously won't be correct.. but that shouldn't make a difference on the issue of ambiguity.

If it was a -T would that have equal precedence as the (S)?

really trying to comprehend how this occurs with it looping back to the Start state.

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

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

发布评论

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

评论(1

ㄟ。诗瑗 2024-10-22 06:09:37

如果将 -S 更改为 -T,歧义就解决了。
在更改之前,这里是一个歧义句的示例:-ab。是-(ab),还是(-a)-b?

然而,随着变化,不再有任何歧义。

至于优先级,在您的具体示例中, -T 和 (S) 之间不必有规则,因为它始终是具有优先级的内部规则,这正是您所期望的行为。

If you change -S to -T, the ambiguity is solved.
Before the change, here is an example for an ambiguous sentence: -a-b. Is it -(a-b), or (-a)-b?

With the change, however, there is no more ambiguity.

As for precedence, in your specific example, there doesn't have to be a rule between -T and (S), since it is always the inner one that has precedence, which is exactly the behavior you would expect.

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