バイソンを使って文法分析を書きます。私は次のようないくつかの優先ルールを見つけました:
%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).
解決できません。助けてください!