[antlr-interest] synpred busted for parametrised rules

David Holroyd dave at badgers-in-foil.co.uk
Mon Jan 1 12:59:52 PST 2007


[I downloaded and compiled the ANTLR source earlier today.]

In my grammar, I have the following rules,

relationalExpression[int inAllowed]
    :   (    shiftExpression
             -> shiftExpression
        )
        (    relationalOperator[inAllowed] shiftExpression
             -> ^(relationalOperator $relationalExpression
                                     shiftExpression)
        )*
    ;

relationalOperator[int inAllowed]
    :    {inAllowed==ALLOW_IN}? IN
    |    LT | GT | LE | GE | isKeyword | asKeyword | 'instanceof'
    ;

When compiling the grammar, ANTLR gives "Decision can match input ..
using multiple alternatives" warnings for relationalExpression and so
(I'm assuming) adds a syntactic predicate to disable the second alt.

However, the generated predicate looks like this:

  public void synpred7_fragment() throws RecognitionException {   
      // as3.g3:781:21: ( relationalOperator[inAllowed] )
      // as3.g3:781:22: relationalOperator[inAllowed]
      {
      pushFollow(FOLLOW_relationalOperator_in_synpred73344);
      relationalOperator(inAllowed);
      _fsp--;
      if (failed) return ;

      }
  }

Which doesn't compile, since 'inAllowed' is not passed to this method.

If I add '(relationalOperator[inAllowed])=>' by hand to disable the
warnings, the same sort of thing happens.

Is the eventual aim to allow code like this to work, or is this
something unsupported which just lacks better error reporting at the
moment?

I'll try to convert the code to use a global scope for the moment.


ta,
dave

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


More information about the antlr-interest mailing list