此 yacc 代码中是否存在移位/归约错误?

发布于 2024-08-12 04:29:07 字数 406 浏览 1 评论 0原文

我收到 yacc 发来的消息,说存在移位/归约冲突。我认为它来自 yacc 文件的这一部分。

statement : expression_stmt
          | compound_stmt
          | selection_stmt
          | iteration_stmt
          | return_stmt ;

selection_stmt : IF '(' expression ')' statement
               | IF '(' expression ')' statement ELSE statement ;

expression : var '=' expression | simple_expression ;

你能看到冲突吗?如何解决?

I'm getting a message from yacc saying that there is a shift/reduce conflict. I think it's coming from this part of the yacc file.

statement : expression_stmt
          | compound_stmt
          | selection_stmt
          | iteration_stmt
          | return_stmt ;

selection_stmt : IF '(' expression ')' statement
               | IF '(' expression ')' statement ELSE statement ;

expression : var '=' expression | simple_expression ;

Can you see a conflict? How can it be fixed?

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

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

发布评论

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

评论(1

风铃鹿 2024-08-19 04:29:07

是的,我看到了冲突。 selection_statement 规则匹配

IF(<expression 1>)
THEN
    IF(<expression 2>)
    THEN <expression statement 1>
    ELSE <expression statement 2>

But that's ambigacy 这样的表达式。也可能是

IF(<expression 1>)
THEN
    IF(<expression 2>)
    THEN <expression statement 1>
ELSE <expression statement 2>

Yes, I'm seeing a conflict. The selection_statement rule matches expressions like

IF(<expression 1>)
THEN
    IF(<expression 2>)
    THEN <expression statement 1>
    ELSE <expression statement 2>

But that's ambiguous. It could also be

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