2014-10-16 115 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