I'm currently working on visual basic converter using jison, and I have these conflicts in my grammar:
Conflict in grammar: multiple actions possible when lookahead token is ELSE in state 11
- reduce by rule: If -> IfBlock
- shift token (then go to state 16)
Conflict in grammar: multiple actions possible when lookahead token is ELSE_IF in state 11
- reduce by rule: If -> IfBlock
- shift token (then go to state 17)
Conflict in grammar: multiple actions possible when lookahead token is TERMINATOR in state 27
- reduce by rule: IfBlock -> IF Expression THEN Body
- shift token (then go to state 13)
Conflict in grammar: multiple actions possible when lookahead token is TERMINATOR in state 29
- reduce by rule: IfBlock -> IfBlock ELSE_IF Expression THEN Body
- shift token (then go to state 13)
States with conflicts:
State 11
If -> IfBlock . #lookaheads= $end TERMINATOR IF_END ELSE ELSE_IF SUB_END
If -> IfBlock .ELSE Body IF_END #lookaheads= $end TERMINATOR IF_END ELSE ELSE_IF SUB_END
IfBlock -> IfBlock .ELSE_IF Expression THEN Body #lookaheads= $end ELSE ELSE_IF TERMINATOR SUB_END IF_END
State 27
IfBlock -> IF Expression THEN Body . #lookaheads= $end ELSE ELSE_IF TERMINATOR SUB_END IF_END
Body -> Body .TERMINATOR Line
Body -> Body .TERMINATOR
State 29
IfBlock -> IfBlock ELSE_IF Expression THEN Body . #lookaheads= $end ELSE ELSE_IF TERMINATOR SUB_END IF_END
Body -> Body .TERMINATOR Line
Body -> Body .TERMINATOR
Here is simplified version of my grammar (actions deleted):
const grammar = {
Root: [
[
''
],
[
'Body'
]
],
Body: [
[
'Line'
],
[
'Body TERMINATOR Line'
],
[ 'Body TERMINATOR' ]
],
Line: [ [ 'Expression' ], [ 'Statement' ] ],
Statement: [ [ 'Return' ], [ 'If' ] ],
Expression: [ [ 'Code' ] ],
Return: [
[
'RETURN Expression'
],
[
'RETURN'
]
],
Code: [
[
'SUB_START Identifier PARAM_START ParamList PARAM_END TERMINATOR Body SUB_END'
]
],
IfBlock: [
[
'IF Expression THEN Body'
],
[
'IfBlock ELSE_IF Expression THEN Body'
]
],
If: [
[ 'IfBlock' ],
[
'IfBlock ELSE Body IF_END'
]
]
}
The conflict is happening when I'm trying to implement a rule for If statement, it seems to conflict with the Body rule.
I spent almost a day trying to solve it, but I can't. I know that the parser can look only one token ahead, but I can't figure out solution by myself. And I'm bound to jison so I cannot use another parser generator. Is there any workaround for my grammar?