[antlr-interest] How to Read ANTLR Ambiguous Path Visualization?

Jim Idle jimi at temporal-wave.com
Mon Mar 21 08:38:58 PDT 2011


looks like ruleunop should be one level higher in the expression tree. Are
you trying to type in a grammar straight from a spec by any chance? Specs
are rarely written in LL(k) form as they are more descriptions of a
language perhaps for programmers and so on, but not usually for parser
writers. You will have to left disambiguate as you read the spec, and then
express it in LL terms. Unfortunately only experience will tell you how to
do this well. It looks like you have basically typed in all the things
that ruleExpression can be, but not in any kind of structured form. If it
is a simple language, then it should be easy enough to sort out.

Here is why you have an ambiguity (not a disambiguity):

1) See a ruleunop, which is followed by another ruleexpression.
2) At the end of that rule expression, the [ can be consumed, or it can be
left to the end of the first expression. Ther is no way to no which
expression it should belong to.

So:

ruleExpression
  : ruleUnop exprlevel2
  | exprlevel2
  ;

exprlevel2
   : exprlevel3 rulesSelector?
   ;

exprlevel3
  : the other stuff ...


Should begin to give you some hints on structure.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Martin Becker
> Sent: Monday, March 21, 2011 6:14 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] How to Read ANTLR Ambiguous Path
> Visualization?
>
> Hi there,
>
> I'm new to grammars and ANTLR(Works) and having a problem now. I
> understand there is some disambiguity in my grammar, but due to lack of
> documentation of the 'Ambiguous Path Visualization' in ANTLRWorks, I
> don't understand what it is trying to tell me. Please have a look at
> this screenshot: http://picfront.de/d/87zv
>
> The error is "Decision can match input such as "'['" using multiple
> alternatives: 1, 2"
>
> Please note that the line between the state "ruleSelector" in the upper
> right corner and the rule "ruleSelector" on the left side is green and
> red, so this seems to be a path for both alternatives.
>
> First of all...does it mean, that the disambiguity starts at the upper
> right corner, before "ruleSelector"? And then...the red path is just
> confusing. I don't understand from where to where it goes...
>
> Could anyone explain that to me, please?
>
> Thanks, Martin
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list