For the following rule :
switchBlockLabels
: ^(SWITCH_BLOCK_LABEL_LIST switchCaseLabel* switchDefaultLabel? switchCaseLabel*)
;
I got an error:”rule switchBlockLabels has non-LL descision due to recursive rule invocations reachable from alts 1,2″.And I tried to add syntactic predicate to solve this problem.I read the book “The Definitive ANTLR Reference”.And Now I am confused that since there is no alternatives in rule switchBlockLabels,then no decision need to be made on which one to choose.
Is anyone can help me?
Whenever the tree parser stumbles upon, say, 2
switchCaseLabels (and noswitchDefaultLabelin the middle), it does not know to which theseswitchCaseLabels belong. There are 3 possibilities the parser can choose from:switchCaseLabels are matched by the 1stswitchCaseLabel*;switchCaseLabels are matched by the 2ndswitchCaseLabel*;switchCaseLabelis matched by the 1stswitchCaseLabel*, and one by the 2ndswitchCaseLabel*.and since the parser does not like to choose for you, it emits an error.
You need to do something like this instead:
That way, when there are only
switchCaseLabels, and noswitchDefaultLabel, theseswitchCaseLabels would be always matched by the firstswitchCaseLabel*: there is no ambiguity anymore.