[antlr-interest] Invalid rule text

Gerz, Michael Gerz at fgan.de
Mon Jun 9 23:30:49 PDT 2008


Dear Bernardo,

> I'm assuming you're using Antlr 3.

Yes.

> I think if you make the change I show below, you should get the list 
> you want:

> expressionList
>   @after {         System.out.println($s); }
>    :
>        { System.out.println("Start"); }
>
>        ( s+=expression   { System.out.println($expression.text); }   )+
>
>        { System.out.println("End: "); }
>    ;

Unfortunately, this code does not compile, because "s.start" is invalid (see code below):

I am also wondering whether your proposal would preserve the commas separating the individual expressions in the expressionList (they were part of the input but no token was added to the tree).

Any other suggestions?

Thanks in advance,

Michael

    // $ANTLR start expressionList
    // JavaCodeGenerator.g:620:1: expressionList : (s+= expression )+ ;
    public final JavaCodeGenerator.expressionList_return expressionList() throws RecognitionException {
        JavaCodeGenerator.expressionList_return retval = new JavaCodeGenerator.expressionList_return();
        retval.start = input.LT(1);

        List list_s=null;
        RuleReturnScope s = null;
        try {
            // JavaCodeGenerator.g:622:5: ( (s+= expression )+ )
            // JavaCodeGenerator.g:623:9: (s+= expression )+
            {
             System.out.println("Start"); 
            // JavaCodeGenerator.g:625:9: (s+= expression )+
            int cnt54=0;
            loop54:
            do {
                int alt54=2;
                int LA54_0 = input.LA(1);

                if ( (LA54_0==CastExpression||(LA54_0>=PostfixDecrement && LA54_0<=PrimarySelector)||(LA54_0>=UnaryMinus && LA54_0<=UnaryPlus)||LA54_0==100||LA54_0==107||(LA54_0>=118 && LA54_0<=120)||(LA54_0>=137 && LA54_0<=164)||(LA54_0>=167 && LA54_0<=168)) ) {
                    alt54=1;
                }


                switch (alt54) {
            	case 1 :
            	    // JavaCodeGenerator.g:625:11: s+= expression
            	    {
            	    pushFollow(FOLLOW_expression_in_expressionList2341);
            	    s=expression();

            	    state._fsp--;

            	    if (list_s==null) list_s=new ArrayList();
            	    list_s.add(s.getTemplate());

            	     System.out.println((s!=null?(input.getTokenStream().toString(
            	      input.getTreeAdaptor().getTokenStartIndex(s.start),
            	      input.getTreeAdaptor().getTokenStopIndex(s.start))):null)); 

            	    }
            	    break;

            	default :
            	    if ( cnt54 >= 1 ) break loop54;
                        EarlyExitException eee =
                            new EarlyExitException(54, input);
                        throw eee;
                }
                cnt54++;
            } while (true);

             System.out.println("End: "); 

            }

                     System.out.println(list_s); 
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end expressionList



************************************************************************
Dr. Michael Gerz 
FGAN e.V.                                       Phone: +49 228 9435-414
Department FKIE/ITF                             Fax: +49 228 9435-685
Neuenahrer Straße 20                            E-Mail: gerz at fgan.de 
53343 Wachtberg-Werthhoven, Germany             WWW: www.fgan.de 
 
Forschungsgesellschaft für Angewandte Naturwissenschaften e. V. (FGAN) 
Sitz der Gesellschaft: Bonn 
Registergericht: Amtsgericht Bonn VR 2530 
Vorstand: Dr.rer.nat. R. Dornhaus (Vorst.), Prof. Dr. J. Ender (Stellv.)
 



More information about the antlr-interest mailing list