0

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

%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).

我无法解决,请帮助我!

4

1 回答 1

1

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

换句话说,没有问题。

于 2013-03-15T18:25:15.213 回答