在尝试设置我的 Jison 语法时,我有:
%left 'OR' 'AND'
%%
Expression:
Operation
;
Operation:
Expression Operator Expression {$$ = new yy.LogicalExpression($2, $1, $3)}
;
Operator:
'AND'
| 'OR'
;
但这导致了以下冲突消息:
Conflict in grammar: multiple actions possible when lookahead token is OR in state 6
- reduce by rule: Operation -> Expression Operator Expression
- shift token (then go to state 5)
Conflict in grammar: multiple actions possible when lookahead token is AND in state 6
- reduce by rule: Operation -> Expression Operator Expression
- shift token (then go to state 4)
States with conflicts:
State 6
Operation -> Expression Operator Expression . #lookaheads= $end OR AND
Operation -> Expression .Operator Expression
Operator -> .AND
Operator -> .OR
当我替换消除Operator
非终端并直接写出表达式模式时:
%left 'OR' 'AND'
%%
Expression:
Operation
;
Operation:
Expression 'AND' Expression {$$ = new yy.LogicalExpression($2, $1, $3)}
| Expression 'OR' Expression {$$ = new yy.LogicalExpression($2, $1, $3)}
;
我没有收到这样的错误,为什么第一个语法有冲突,而第二个没有?它们似乎与我的理解相当。
提前致谢!