[antlr-interest] Code generation bug in tree parser (ANTLRV3b6)

Dr. Hartmut Kocher hwk.cortex-brainware at t-online.de
Wed Feb 28 15:04:07 PST 2007


In my tree parser I get several instances of the form:

 

case 45:

       int LA7_4 = input.LA(2);

       if ( (LA7_4 == DOWN) )

       {

 

This doesn’t compile as there is no token constant “DOWN” defined in the
parser.

 

There are two possible ways to fix this: Either generate    public const int
DOWN = 2; into the file, or generate “Token.DOWN” wherever it is used.

 

As I don’t know which is the intended behavior, I hacked Target.java for now
to return “Token.DOWN” instead of “DOWN”.

 

/** Target must be able to override the labels used for token types */

            public String getTokenTypeAsTargetLabel(CodeGenerator generator,
int ttype) {

                        String name =
generator.grammar.getTokenDisplayName(ttype);

                        // If name is a literal, return the token type
instead

                        if ( name.charAt(0)=='\'' ) {

                                   return String.valueOf(ttype);

                        }

                        // HACK!!!

                        if(name.equals("DOWN")) {

                                   name = "Token.DOWN";

                        }

                        return name;

            }

 

Same might happen with „UP“ as this is also excluded from the token
definition list


 

Please put his in the bug list.

 

Kind regards

 

Dr. Hartmut Kocher

Cortex Brainware Consulting & Training GmbH

Kirchplatz 5
D-82049 Pullach

Tel: +49 (89) 744  850 0
Fax: +49 (89) 744  850 11

 <http://www.cortex-brainware.de/> http://www.cortex-brainware.de

E-Mail: hwk at cortex-brainware.de

Handelsregister:
Registergericht: Amtsgericht München
HRB-Nr. 120614

Vertretungsberechtigte Geschäftsführer:
Dipl.-Inform. Dorothea Burger, Dr.-Ing. Hartmut Kocher, Dr.-Ing. Martin
Lang, Dr. rer. nat. Rolf Peter Wehrum 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070301/be15a46a/attachment.html 


More information about the antlr-interest mailing list