野牛的规则优先级

发布于 2024-08-23 15:14:42 字数 390 浏览 11 评论 0原文

这是语法规则:

ProcessExpression :  EventExpression "->" ProcessExpression

                    | ProcessName ;

请你告诉我如何告诉 bison 第一个规则比第二个规则具有最高优先级?

我已经尝试过:

%nonassoc PROC

%right "->"

ProcessExpression :  EventExpression "->" ProcessExpression

                    | ProcessName % prec PROC;

但没有任何结果。 谢谢。

Here is the grammar rules:

ProcessExpression :  EventExpression "->" ProcessExpression

                    | ProcessName ;

Please can you tell me how can I tell to bison that the first rule has the highest precedence than the second one?

I have tried:

%nonassoc PROC

%right "->"

ProcessExpression :  EventExpression "->" ProcessExpression

                    | ProcessName % prec PROC;

But without any result.
Thank you.

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

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

发布评论

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

评论(2

無處可尋 2024-08-30 15:14:42

为了解决归约/归约冲突,bison 按照规则在源文件中的顺序赋予规则优先级,因此通过成为第一个规则,第一个规则具有更高的优先级。但这显然不是你想要的,否则你不会问这个问题。

使用 %nonassoc/%right 会优先考虑用于解决移位/归约冲突的标记。在这种情况下,重要的是令牌的优先级转变为要降低的规则的优先级。仅涉及一个规则(尽管其他规则可能在当前状态下部分解析),因此在这种情况下谈论一个规则比另一个规则具有更高或更低的优先级是没有意义的。

那么你想做什么?究竟出了什么问题? EventExpressionProcessName 是否有些相似,因此存在冲突?您没有提供有关这些规则是什么的信息......

For resolving reduce/reduce conflicts, bison gives rules precedence in the order they are in the source file, so by being first, the first rule has higher precedence. But that is apparently not what you want, or you wouldn't be asking this question.

Using %nonassoc/%right gives precedences to tokens for resolving shift/reduce conflicts. In this case what matters is the precedence of a token to shift to the precedence of a rule to be reduced. There's only one rule involved (though other rules may exist partially parsed in the current state), so it makes no sense to talk about one rule having higher or lower precedence than another in this situation.

So what is it you're trying to do? What exactly is going wrong? Are EventExpression and ProcessName somewhat similar so they have conflicts? You give no information about what those rules are...

可爱暴击 2024-08-30 15:14:42

我认为,只有当存在左递归时,您才能应用您所写的内容。所以尝试这样的事情。

%nonassoc PROC
%left EVENT

ProcessExpression :  EventExpression "->" ProcessExpression %prec EVENT

                    | ProcessName % prec PROC;

谢谢,
戈库尔。

I think, you can apply what you have written, only when there is a left recursion. So try something like this.

%nonassoc PROC
%left EVENT

ProcessExpression :  EventExpression "->" ProcessExpression %prec EVENT

                    | ProcessName % prec PROC;

Thanks,
Gokul.

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