从 bison 或 yacc 过滤 y.output?

发布于 2024-08-23 00:55:07 字数 98 浏览 8 评论 0原文

我正在使用 bison,通过查看 y.output 很难找出冲突。是否有工具可以制作或过滤 y.output 使其更有用?我很想看到进入冲突状态的完整路径,但我想要任何有帮助的东西。

I am using bison and its difficult to figure out the conflicts by looking at y.output. Is there a tool to make or filter y.output so its more useful? i would love to see the full path to the state with the conflict but anything helpful is what i would like.

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

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

发布评论

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

评论(1

甜妞爱困 2024-08-30 00:55:07

我假设您知道什么是移位/减少和减少/减少冲突以及它们何时发生。鉴于此,我所做的只是使用 vim...

在 y.output 的顶部,它列出了哪些状态有多少冲突。如果您只需输入“/statenumber”并按“n”几次,您应该能够直接进入该状态的转换。

在那里,您将看到用“.”输入的产生式规则。在他们之中。点表示产生式规则中已解析到的位置。如果点位于末尾,则意味着它将尝试“减少”,如果不是,则尝试“移动”。如果下一个标记位于 LHS 非终结符的 FOLLOWSET 中(下一个标记是可以跟随该非终结符的符号),则发生减少产生式,并且对于终结符或 FIRST(非终结符)发生移位在“.”之后。

如果对于下一个可能的标记有两种可能的移动(移位/归约或归约/归约),则会发生冲突。

当您发现冲突时,只需进入该状态,找出哪些产生式规则给您带来冲突,然后: a - 修改语法以消除该冲突,或 b - 使用 %prec 表示法指定产生式规则优先级。

希望有帮助:)

I assume you know what shift/reduce and reduce/reduce conflicts are and when they occur. Given that, what I did was just use vim...

At the top of y.output, it lists which states have how many conflicts. If you just type "/statenumber" and press 'n' a couple of times, you should be able to go straight to the transitions for that state.

There, you'll see the production rules you typed with a '.' in them. The dot indicates the place in the production rule up to which it has parsed. If the dot is at the end, that means that it'll attempt a 'reduce', and if not, a 'shift'. A reduce production occurs if the next token is in the FOLLOWSET of the LHS non-terminal (the next token is a symbol that can follow that non-terminal), and a shift occurs for the terminal or FIRST(non-terminal) that is after the '.'.

A conflict occurs if you have two possible moves (shift/reduce or reduce/reduce) for a possible next token.

When you find conflicts, simply go to that state, find out which production rules are giving you the conflict, and either: a -- modify your grammar to remove that conflict, or b -- specify production rule precedence using the %prec notation.

Hope that helped :)

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