2014-10-16 113 views
0

我正在編寫一個SQL編譯器在野牛和無法解釋狀態機野牛的生產。以下是導致1 reduce/reduce錯誤的兩種狀態。野牛:減少/減少衝突

我猜not_qm導致這些reduce/recudelike_condin_cond(見下面的代碼)。

我希望有人能指出我正確的方向。請讓我知道是否需要更多信息。

like_cond : scalar_exp not_qm LIKE scalar_exp escape_scalar_exp_qm 
      ; 

in_cond : row_constructor not_qm IN LPAREN table_exp RPAREN 
      | scalar_exp not_qm IN LPAREN scalar_exp_list RPAREN 
      ; 

not_qm  : /* empty */ 
      | NOT 
      ; 

### EDITTED SECTION 
row_constructor  : scalar_exp 
        | LPAREN scalar_exp_list RPAREN 
        ; 

scalar_exp   : un_op_qm scalar_primary 
        | scalar_exp bin_op scalar_primary 
        ; 
### 


State 193 

35 like_cond: scalar_exp . not_qm LIKE scalar_exp escape_scalar_exp_qm 
37 in_cond: scalar_exp . not_qm IN LPAREN scalar_exp_list RPAREN 
75 row_constructor: scalar_exp . 
78 scalar_exp: scalar_exp . bin_op scalar_primary 

STAR shift, and go to state 59 
NOT  shift, and go to state 218 
PLUS shift, and go to state 60 
MINUS shift, and go to state 61 
DIV  shift, and go to state 62 
CONCAT shift, and go to state 63 

NOT  [reduce using rule 75 (row_constructor)] 
LIKE  reduce using rule 148 (not_qm) 
IN  reduce using rule 75 (row_constructor) 
IN  [reduce using rule 148 (not_qm)] 
$default reduce using rule 75 (row_constructor) 

bin_op go to state 64 
not_qm go to state 228 

State 211 

35 like_cond: scalar_exp . not_qm LIKE scalar_exp escape_scalar_exp_qm 
37 in_cond: scalar_exp . not_qm IN LPAREN scalar_exp_list RPAREN 
75 row_constructor: scalar_exp . 
78 scalar_exp: scalar_exp . bin_op scalar_primary 
123 scalar_exp_list: scalar_exp . scalar_exp_list_star 

STAR shift, and go to state 59 
NOT  shift, and go to state 218 
PLUS shift, and go to state 60 
MINUS shift, and go to state 61 
DIV  shift, and go to state 62 
CONCAT shift, and go to state 63 
COMMA shift, and go to state 109 

RPAREN reduce using rule 124 (scalar_exp_list_star) 
NOT  [reduce using rule 75 (row_constructor)] 
LIKE  reduce using rule 148 (not_qm) 
IN  reduce using rule 75 (row_constructor) 
IN  [reduce using rule 148 (not_qm)] 
$default reduce using rule 75 (row_constructor) 

bin_op    go to state 64 
scalar_exp_list_star go to state 110 
not_qm    go to state 228 
+0

你可以顯示你用於'scalar_exp'和'row_constructor'的規則嗎? – kraskevich 2014-10-16 18:16:21

+0

我將它們添加到我的開始信息 – Wouter 2014-10-16 18:18:34

回答

0

問題是與這3個原則:

1)row_constructor not_qm IN LPAREN table_exp RPAREN 
2)scalar_exp not_qm IN LPAREN scalar_exp_list RPAREN 
3)row_constructor  : scalar_exp 

看,如果在堆棧上的最後一個元素是scalar_exp和下一標記IN會發生什麼: 它可以減少一個空字符串not_qm,以便堆棧變爲scalar_exp, not_qm或它可以將scalar_exp減少到row_constructor。它發生是因爲bison生成一個LALR(1)解析器,所以它只根據堆棧的頂層元素和下一個標記作出決定。這就是爲什麼在這一點上它不能區分1)2)規則,儘管它們是不同的。所以你需要改變你的語法,使其成爲LALR(1)可分的。

+0

感謝您的幫助。所以問題是建立一個使用大小爲1的超前分析器的野牛?我編輯我的語法爲LALR(1)有效,減少/減少衝突消失。 – Wouter 2014-10-16 20:06:14

+0

@Wouter是的,它使用LALR(1)解析,因爲這種類型的解析器在時間和內存使用方面更加高效。 – kraskevich 2014-10-16 20:17:12