AW: [antlr-interest] Problem: part of AST gets lost in limbo

Koehne Kai Kai.Koehne at student.hpi.uni-potsdam.de
Thu Jun 8 11:09:42 PDT 2006


Hi Ulrich,
 
> sts:(statement)*
 
this will not work. According to the manual, only atomic or rule reference production elements can be labeled:
http://www.antlr.org/doc/metalang.html#_bb16
 
Instead of referencing (statement)* directly, you can use #lc.getNextSibling().
 
Regards,

Kai Koehne

________________________________

Von: antlr-interest-bounces at antlr.org im Auftrag von Ulrich Hobelmann
Gesendet: Do 08.06.2006 17:07
An: antlr-interest at antlr.org
Betreff: [antlr-interest] Problem: part of AST gets lost in limbo



Hi, I'm using the Antlr Java 1.5 grammar + tree parser, working nicely.

My problem: in one instance now a part of the parsed AST gets lost 
between the parser and tree parser.  The tree parser only receives 
part of the expression; the rest is simply lost.

This happens in the java15.g file in the production 
"compoundStatement", which I modified as follows:

compoundStatement!
        :       lc:LCURLY! //^ {#lc.setType(SLIST);}
                        // include the (possibly-empty) list of statements
                        sts:(statement)*
                rc:RCURLY!
         {
             /* wrap the line numbers as an IDENT string and smuggle 
them through ;-) */
             #compoundStatement =
                 #(#[SLIST,"SLIST"],
                   #[IDENT,Integer.toString(lc.getLine())],
                   #[IDENT,Integer.toString(rc.getLine())],
                   sts);
         }
        ;

I also put a println() inside the "sts:(statement)*" to ensure that 
it works, and indeed it prints several lines as it should.  Now the 
part of the tree parser seems to not receive the "sts" part:

slist { ... return and variable decls ... }
        :       #( SLIST l1:IDENT l2:IDENT (e1=stat
                 {
                     System.out.println("STATEMENT");
                 }
             )*)
         //#( SLIST (stat)*)
        ;

For some reason the list of statements exists in the parser, but in 
the tree parser STATEMENT doesn't print even once.  I can only think 
that there must be something wrong with my expression in the parser 
"compoundStatement", but other expressions seem to be written the 
same way, with no problem at all...

Any ideas?

Regards,
   Ulrich




More information about the antlr-interest mailing list