CFG 算术优先级/歧义
自从我与 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将 -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.