[antlr-interest] Latest intermediate build (ANTLR 3.1b1) produces broken Java code

Gerz, Michael Gerz at fgan.de
Tue Apr 29 21:55:18 PDT 2008


Hi,

I encountered a problem with the latest ANTLR snapshot. The problem does not occur with ANTLR 3.0.1.

The following (simplified) rule:


record 
            :           {
                                    List<SyLTParameter> syltPars = classDoc.getConstructors().get(0).getParameters();
                                   int parNo = 0;
                                   boolean first = true;
                        }
            
                        '{' 

                        (           { parNo < syltPars.size() }? =>
              
                                    (           { first  }? => { first = false; }
                                    |           { !first }? => ',' )

                                   f = field[type, false] 
                        )*
                
                        '}'
            ;

leads to the following broken code:

    public final void record() throws RecognitionException {
        try {
            // Message.g:94:2: ( '{' ({...}? => ({...}? => | {...}? => ',' ) f= field[type, false] )* '}' )
            // Message.g:94:4: '{' ({...}? => ({...}? => | {...}? => ',' ) f= field[type, false] )* '}'
            {
                            List<SyLTParameter> syltPars = classDoc.getConstructors().get(0).getParameters();
                             int parNo = 0;
                             boolean first = true;
       }
                        
            match(input,25,FOLLOW_25_in_record212); 
            // Message.g:112:3: ({...}? => ({...}? => | {...}? => ',' ) f= field[type, false] )*
            loop2:
            do {
                int alt2=2;
                alt2 = dfa2.predict(input);
                  ... more code ...
            } while (true);

            match(input,27,FOLLOW_27_in_record306); 
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
    }

    class DFA2 extends DFA {

        public DFA2(BaseRecognizer recognizer) {
            this.recognizer = recognizer;
            this.decisionNumber = 2;
            this.eot = DFA2_eot;
            this.eof = DFA2_eof;
            this.min = DFA2_min;
            this.max = DFA2_max;
            this.accept = DFA2_accept;
            this.special = DFA2_special;
            this.transition = DFA2_transition;
        }
        public String getDescription() {
            return "()* loopback of 112:3: ({...}? => ({...}? => | {...}? => ',' ) f= field[type, false] )*";
        }
        public int specialStateTransition(int s, IntStream _input) throws NoViableAltException {
            TokenStream input = (TokenStream)_input;
            int _s = s;
            switch ( s ) {
                    case 0 : 
                        int LA2_0 = input.LA(1);

                         
                        int index2_0 = input.index();
                        input.rewind();
                        s = -1;
                        if ( (LA2_0==27) ) {s = 1;}
                        else if ( (LA2_0==DECIMAL_LITERAL) && (( parNo < syltPars.size() && first  ))) {s = 2;}
                        else if ( (LA2_0==FLOATING_POINT_LITERAL) && (( parNo < syltPars.size() && first  ))) {s = 3;}
                        else if ( (LA2_0==CHARACTER_LITERAL) && (( parNo < syltPars.size() && first  ))) {s = 4;}
                        else if ( (LA2_0==STRING_LITERAL) && (( parNo < syltPars.size() && first  ))) {s = 5;}
                        else if ( (LA2_0==IDENTIFIER) && (( parNo < syltPars.size() && first  ))) {s = 6;}
                        else if ( (LA2_0==TRUE) && (( parNo < syltPars.size() && first  ))) {s = 7;}
                        else if ( (LA2_0==FALSE) && (( parNo < syltPars.size() && first  ))) {s = 8;}
                        else if ( ((LA2_0>=NULL && LA2_0<=OMIT)) && (( parNo < syltPars.size() && first  ))) {s = 9;}
                        else if ( (LA2_0==25) && (( parNo < syltPars.size() && first  ))) {s = 10;}
                        else if ( (LA2_0==28) && (( parNo < syltPars.size() && first  ))) {s = 11;}
                        else if ( (LA2_0==26) && (( parNo < syltPars.size() && !first ))) {s = 12;}
                       
                        input.seek(index2_0);
                        if ( s>=0 ) return s;
                        break;
            }
            NoViableAltException nvae =
                new NoViableAltException(getDescription(), 2, _s, input);
            error(nvae);
            throw nvae;
        }
    }



Obviously, DFA2.specialStateTransition refers to the local variables defined within record(), i.e. "parNo", "syltPars", and "first". 

Any idea on how to fix this issue? Or is this in fact a new "feature"?

Many thanks in advance!

Michael



************************************************************************
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.)


************************************************************************
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