规则18和令牌ADD之间的冲突解决为reduce(ADD< UMINUS)

时间:2013-03-15 06:23:27

标签: bison yacc lex

我用野牛写了一个语法分析。我确定了一些优先规则,如:

%right EQUAL
%left OR AND
%left ADD SUB
%left MUL DIV MOD
%nonassoc UMINUS

然后我就像使用它们一样:

math
: math ADD math {$$ = math_add($1,$3);}
| math OR math {$$ = math_or($1,$3);}
| math AND math {$$ = math_and($1,$3);}
| math SUB math {$$ = math_sub($1,$3);}
| math MUL math {$$ = math_mul($1,$3);}
| math DIV math {$$ = math_div($1,$3);}
| math MOD math {$$ = math_mod($1,$3);}
| SUB math %prec UMINUS {$$ = math_unary_uminus($2);}
| PARENTHESIS math CLOSE_PARENTHESIS {$$ = $2;}
| literal {$$ =$1;}
| reference {$$ = $1;}

运行,它会生成一个包含一些冲突的.output文件:

state 33 
11 math: math . ADD math
12     | math . OR math
13     | math . AND math
14     | math . SUB math
15     | math . MUL math
16     | math . DIV math
17     | math . MOD math
18     | SUB math .  [ADD, SUB, MUL, DIV, MOD, OR, AND, CLOSE_PARENTHESIS]

 $default  reduce using rule 18 (math)

 Conflict between rule 18 and token ADD resolved as reduce (ADD < UMINUS).
 Conflict between rule 18 and token SUB resolved as reduce (SUB < UMINUS).
 Conflict between rule 18 and token MUL resolved as reduce (MUL < UMINUS).
 Conflict between rule 18 and token DIV resolved as reduce (DIV < UMINUS).
 Conflict between rule 18 and token MOD resolved as reduce (MOD < UMINUS).
 Conflict between rule 18 and token OR resolved as reduce (OR < UMINUS).
 Conflict between rule 18 and token AND resolved as reduce (AND < UMINUS).

我无法解决,请帮助我!

1 个答案:

答案 0 :(得分:1)

据推测,您使用bison选项(或-r all)运行--report=all,其中包含solved报告(“描述转换/解决冲突解决”)。这就是它正在做的事情:它描述了它如何通过使用您提供的优先规则来解决转移/解决冲突。

换句话说,没有问题。