野牛转移/减少错误

时间:2015-03-21 15:08:11

标签: bison

我在野牛中有一个错误,我不知道如何解决。

在尝试编译语法时,我得到1个shift / reduce错误:

START: type_specifier MAIN LBR_R RBR_R LBR_C program RBR_C

program: statement ; 

type_specifier: INT | DOUBLE | VOID;


var_declaration: type_specifier var_declist SECOLON;

var_declist: var_declist COMMA var_intialise | var_intialise;

var_intialise: var_ID | var_ID EQL simple_expression; 



assign : var_ID EQL simple_expression SECOLON; 


statement: expression_stmt | local_declaration | selection_stmt | iteration_stmt| return_stmt | break_stmt; 

local_declaration: var_declaration | assign; 

expression_stmt: expression SECOLON | SECOLON;

selection_stmt: IF LBR_R simple_expression RBR_R LBR_C statement RBR_C;

iteration_stmt: WHILE LBR_R simple_expression RBR_R LBR_C statement RBR_C;

return_stmt: RETURN SECOLON | RETURN expression SECOLON; 

break_stmt: BREAK SECOLON; 




expression: var_ID EQL expression | var_ID INCR_EQL expression | var_ID DECR_EQL expression | var_ID INCR | var_ID DECR | simple_expression; 

simple_expression: simple_expression OR and_expression | and_expression; 

and_expression: and_expression AND unary_rel_expression | unary_rel_expression; 

unary_rel_expression: NOT rel_expression | rel_expression; 

rel_expression: sum_expression relop sum_expression | sum_expression;

relop: LSS_EQL | LSS | GR | GR_EQL | EQUIV | NOT EQL;

sum_expression: sum_expression sumop term | term; 

sumop: ADD | SUB;

term: term mulop unary_expression | unary_expression; 

mulop: MULT | DIV | RMDR; 

unary_expression: factor; 

factor: immutable | var_ID; 

var_ID: ID;

immutable: LBR_R expression RBR_R | call | constant; 

call: ID LBR_R args RBR_R; 

args:  | arg_list; 

arg_list: arg_list COMMA expression | expression; 
constant: INT | CHAR | STRING; 

我在

获得1班/减少

国家102冲突:1班/减少

具体状态是:

state 102

   11 assign: var_ID EQL simple_expression . SECOLON
   32 expression: simple_expression .  [SECOLON]
   33 simple_expression: simple_expression . OR and_expression

    OR       shift, and go to state 63
    SECOLON  shift, and go to state 111

    SECOLON  [reduce using rule 32 (expression)]

有人可以解释如何修复此错误,我知道它与优先级有关。

1 个答案:

答案 0 :(得分:1)

这与优先权无关。

这是语法的相关子集:

statement: expression_stmt | local_declaration
expression_stmt: expression ';'
expression: var_ID EQL expression | simple_expression
local_declaration: assign
assign: var_ID EQL simple_expression ';'

这显然含糊不清; var = <simple_expression> ;可以是expression_stmtlocal_declaration。这种模糊性通常会导致减少/减少冲突,但在这种情况下,由于您处理分号的方式,您会发生转换/减少冲突。无论如何,解决方案是消除歧义。