无法设置优先级规则来强制转换Jison

时间:2015-10-17 22:18:25

标签: parsing bison context-free-grammar lalr jison

我正在尝试用我的语言实现一个功能,您可以通过执行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中获得shift / reduce冲突警告。我认为优先于最后一条规则而其他所有规则都会这样做,但我得到了这个:

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

非常感谢通过优先规则解决这个问题的任何帮助。

提前谢谢!

0 个答案:

没有答案