2010-07-06 2 views
2

SableCC 및 문법 정의에 처음 경험했습니다. 나는 (그 일부) 다음과 같은 문법을 가지고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 ; 

I가 다음과 같은 오류 :

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 방법으로하는, 가독성을 높여야하지만 우아한 방식으로이를 수행 할 수있는 방법이 있습니까?

감사합니다.

답변

3

그래서 문제를 해결했습니다. 제가 한 것은 기본적으로 세 가지 수준의 연관성을 정의하는 것입니다. + = logic_or, * = logic_and, - = logic_not -

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 ; 

그것은 단항 연산자 등으로 고전적인 연관성 방식 +, *입니다.