[antlr-interest] ambiguity when calling rule
Kay Roepke
kroepke at dolphin-services.de
Thu May 25 09:12:23 PDT 2006
On 25. May 2006, at 10:08 Uhr, Corno wrote:
> Can somebody explain why this is and if there is a way to prevent
> having to
> copy rules?
I'll try my luck:
ANTLR says:
test.g:3:27: Decision can match input such as "'.' 'w' '<' {'x'..'y',
'>'}" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
That means:
Whenever ANTLR enters 'selection' and would match '.w' input it has
to two options for matching the last '.' 'w':
1) do the loop in selection ('.' 'w')* (i.e. the last iteration in
the loop)
2) match the '.' 'w' in rule 'statement'
Without knowing the input (i.e. in analysis) it cannot decide which
option to pick. But it has to decide because there can only be
one edge leading outward from the DFA state it is on. Consequently it
picks one option and discards all the others (in this case it's
only one: alternative 2) [Why is this called alternative? They are
really options not alternatives...sorry pet peeve]
This has nothing to do with lookahead, because for sets as spelled
out in the warning above, it simply cannot be decided which path to
choose.
When adding selection2 there is a different DFA (the one for
selection2) and thus no predicament as to which path to take.
Try it in ANTLRWorks to see the DFAs. Especially not the interpreter.
You can also see the different alts in the graph. Way cool!
Unfortunately I can offer you no solution for this with just one
rule, as I cannot think of anything to add short of semantic
predicates to
differentiate between those two uses of 'selection', but that's
probably a thing you'd like to avoid.
But: What do you actually want to achieve? There might be a way
around this dilemma...
HTH,
-k
More information about the antlr-interest
mailing list