gpt4 book ai didi

shift-reduce-conflict - 转移/减少与 SableCC 的冲突

转载 作者:行者123 更新时间:2023-12-04 06:50:30 27 4
gpt4 key购买 nike

我第一次接触 SableCC 和语法定义。
我有以下语法(其中的一部分):

query =
{atop} attroperator |
{query_par} l_par query r_par |
{query_and} [q1]:query logic_and [q2]:query |
{query_or} [q1]:query logic_or [q2]:query |
{query_not} logic_not query ;

我有以下错误:
shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TRPar in {
[ PQuery = PQuery * TRPar ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TRPar (reduce)
}

shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TLogicAnd in {
[ PQuery = PQuery * TLogicAnd PQuery ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TLogicAnd (reduce)
}

shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TLogicOr in {
[ PQuery = PQuery * TLogicOr PQuery ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TLogicOr (reduce)
}

我通过将 l_par 和 r_par 添加到所有替代方案来解决它们,由
方式,应该提高可读性,但有没有办法做到这一点
优雅的方式?

谢谢。

最佳答案

所以,我已经解决了这个问题。我所做的基本上是定义了三个层次的关联性。

query = 
{query_or} query logic_or term |
{query_term} term ;

term =
{term_and} term logic_and factor |
{term_factor} factor ;

factor =
{atop} attroperator |
{query_not} logic_not attroperator |
{query_par} l_par query r_par ;

这是经典的结合性方案 +,* 带有一元运算符,例如 - where + = logic_or , * = logic_and , - = logic_not .

关于shift-reduce-conflict - 转移/减少与 SableCC 的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3190100/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com