0
我用bison編寫語法分析。我definded一些優先規則,如:規則18和標記ADD之間的衝突解析爲reduce(ADD <UMINUS)
%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).
我可以」 t解決它,請幫助我!