标记如何导致冲突?

发布于 2024-12-26 05:00:37 字数 302 浏览 7 评论 0原文

为什么具有以下规则的语法会导致冲突?

    Statement   |   IF  {...} LP BoolExp RP %prec IFX  Statement { ... }
                |       ...

IFX 终端用于解决悬空 else 的标准技巧。我认为这在某种程度上是相关的。 删除第一个标记即可消除冲突。

野牛输出的消息是:

警告:由于冲突,规则在解析器中无用:$@2: /* 空 */

Why does a grammar with the following rule result in a conflict?

    Statement   |   IF  {...} LP BoolExp RP %prec IFX  Statement { ... }
                |       ...

The IFX terminal is for the standard trick for resolving dangling else. I think that this is somehow related.
Removing the first marking removes the conflict.

The message bison outputs is:

warning: rule useless in parser due to conflicts: $@2: /* empty */

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

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

发布评论

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

评论(1

痴骨ら 2025-01-02 05:00:37

在评论中回答

@sarnold 写道:

我希望这是相关且有用的: http://lists.gnu.org/archive/html/help-bison/2001-10/msg00011.html/

但是,SO 不赞成仅使用网络链接答案。所以我在这里总结一下。
该链接指向@Hans Aberg 题为“Shift 减少由于嵌入操作导致的错误”的回复列表。概括地说,它建议:

解决这个问题的最好方法可能是收集语义
A 和 B 生成的信息,然后在应用 C 或 D 时使用该信息。

(Answered in the comments)

@sarnold wrote:

I hope this is relevant and useful: http://lists.gnu.org/archive/html/help-bison/2001-10/msg00011.html/

However SO deprecates web link only answers. So I summarise here.
The link is to a list reply entitled "Shift reduce errors due to embedded actions" by @Hans Aberg. In outline it suggests:

The best way around this problem is probably to collect the semantic
information that A and B produces and then use that when appyling C or D.

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