[antlr-interest] Several questions

David Holroyd dave at badgers-in-foil.co.uk
Mon Jan 1 10:37:23 PST 2007


Hi,

On Mon, Jan 01, 2007 at 11:58:21AM -0500, Daniel Plaisted wrote:
> 3. If Then Else ambiguity - I have a rule which looks like:
> ifStat : 'if' expr 'then' stat ('else' stat)?;

> ANTLR gives the following warning:
> [15:49:08] warning(200): EasyLanguage.g:111:30: Decision can match
> input such as "'else'" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input

ANTLR is dealing with the grammar ambiguity by removing it for you.

i.e. given that the grammar gives,
  alternative 1: match the "else" now
  alternative 2: exit the (..)? and match the else in an enclosing
                 recursive invocation

it has disabled the second option, which is probably what you want (i.e.
the "else" binds to the closest if..then).

I got the warning to go away in my grammar by using a predicate to
explicitly request this behaviour,

  ifStatement
      :    IF^ condition statement
           ((ELSE)=>ELSE statement)?
      ;

Hopefully that's the correct thing to do.


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list