我正在尝试用我的语言实现一个功能,您可以在通过执行返回函数后执行语句return someVal then someCode()
。
对于 return 语句,我有以下语法:
ReturnStatement:
'RETURN' { $$ = new yy.ReturnStatement(null).pos(@$)}
| 'RETURN' Expression { $$ = new yy.ReturnStatement($2).pos(@$)}
| 'RETURN' Expression 'THEN' Statement %prec 'AFTER' { $$ = new yy.ReturnStatement($2, $4).pos(@$)}
;
在 Jison 文件的标题中,我有以下优先规则:
%nonassoc 'NAME'
%right ':'
%nonassoc 'IF'
%nonassoc 'ENDLN'
%nonassoc 'ELSE'
%nonassoc 'DEF'
%right 'ASSIGN' ''
%left 'YIELD'
%left 'OR'
%left 'AND'
%left '==' '!=' '<' '>' '<=' '>='
%left '+' '-' '&'
%left '*' '//' '%' '/'
%right 'UMIN' 'UPLUS'
%left '^'
%left 'AWAIT'
%right 'TYPEOF'
%right 'UB_FUNC' 'B_FUNC'
%left 'ACCESS'
%nonassoc 'INDEX_LEFT' 'INDEX_RIGHT'
%left 'CALL_LEFT' 'CALL_RIGHT'
%right 'NEW'
%nonassoc 'AFTER'
%%
我知道当存在冲突时,Jison 默认会转移,但我想设置优先规则,这样我就不会在 Jison 中收到转移/减少冲突警告。我认为将最后一条规则设置为优先于所有其他规则会这样做,但我得到了这个:
Conflict in grammar: multiple actions possible when lookahead token is - in state 53
- reduce by rule: Continuation -> YIELD
- shift token (then go to state 63)
Conflict in grammar: multiple actions possible when lookahead token is + in state 53
- reduce by rule: Continuation -> YIELD
- shift token (then go to state 64)
Conflict in grammar: multiple actions possible when lookahead token is - in state 54
- reduce by rule: Continuation -> AWAIT
- shift token (then go to state 63)
Conflict in grammar: multiple actions possible when lookahead token is + in state 54
- reduce by rule: Continuation -> AWAIT
- shift token (then go to state 64)
Conflict in grammar: multiple actions possible when lookahead token is CALL_LEFT in state 131
- reduce by rule: Expression -> MemberExpression
- shift token (then go to state 91)
Conflict in grammar: multiple actions possible when lookahead token is CALL_LEFT in state 132
- reduce by rule: Expression -> Identifier
- shift token (then go to state 91)
Conflict in grammar: multiple actions possible when lookahead token is % in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 87)
Conflict in grammar: multiple actions possible when lookahead token is // in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 86)
Conflict in grammar: multiple actions possible when lookahead token is / in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 85)
Conflict in grammar: multiple actions possible when lookahead token is * in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 84)
Conflict in grammar: multiple actions possible when lookahead token is - in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 83)
Conflict in grammar: multiple actions possible when lookahead token is + in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 82)
Conflict in grammar: multiple actions possible when lookahead token is & in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 81)
Conflict in grammar: multiple actions possible when lookahead token is >= in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 80)
Conflict in grammar: multiple actions possible when lookahead token is <= in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 79)
Conflict in grammar: multiple actions possible when lookahead token is > in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 78)
Conflict in grammar: multiple actions possible when lookahead token is < in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 77)
Conflict in grammar: multiple actions possible when lookahead token is != in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 76)
Conflict in grammar: multiple actions possible when lookahead token is == in state 134
- reduce by rule: Continuation -> YIELD Expression
- shift token (then go to state 75)
Conflict in grammar: multiple actions possible when lookahead token is % in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 87)
Conflict in grammar: multiple actions possible when lookahead token is // in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 86)
Conflict in grammar: multiple actions possible when lookahead token is / in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 85)
Conflict in grammar: multiple actions possible when lookahead token is * in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 84)
Conflict in grammar: multiple actions possible when lookahead token is - in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 83)
Conflict in grammar: multiple actions possible when lookahead token is + in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 82)
Conflict in grammar: multiple actions possible when lookahead token is & in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 81)
Conflict in grammar: multiple actions possible when lookahead token is >= in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 80)
Conflict in grammar: multiple actions possible when lookahead token is <= in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 79)
Conflict in grammar: multiple actions possible when lookahead token is > in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 78)
Conflict in grammar: multiple actions possible when lookahead token is < in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 77)
Conflict in grammar: multiple actions possible when lookahead token is != in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 76)
Conflict in grammar: multiple actions possible when lookahead token is == in state 135
- reduce by rule: Continuation -> AWAIT Expression
- shift token (then go to state 75)
Conflict in grammar: multiple actions possible when lookahead token is == in state 151
- reduce by rule: UnaryExpression -> - Expression
- shift token (then go to state 75)
Conflict in grammar: multiple actions possible when lookahead token is != in state 151
- reduce by rule: UnaryExpression -> - Expression
- shift token (then go to state 76)
Conflict in grammar: multiple actions possible when lookahead token is < in state 151
- reduce by rule: UnaryExpression -> - Expression
- shift token (then go to state 77)
Conflict in grammar: multiple actions possible when lookahead token is > in state 151
- reduce by rule: UnaryExpression -> - Expression
- shift token (then go to state 78)
Conflict in grammar: multiple actions possible when lookahead token is <= in state 151
- reduce by rule: UnaryExpression -> - Expression
- shift token (then go to state 79)
Conflict in grammar: multiple actions possible when lookahead token is >= in state 151
- reduce by rule: UnaryExpression -> - Expression
- shift token (then go to state 80)
...
任何通过优先规则解决此问题的帮助将不胜感激。
先感谢您!