我有以下语法(它的一部分):
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\u par和r\u 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 .
+ = logic_or
* = logic_and
- = logic_not