[antlr-interest] V3 Rule Action allowing inline tree building?

Lucien Antlr lucien_antlr at yahoo.com
Wed Mar 18 09:53:29 PDT 2009


Hi folks,

I saw back in 2005 there was a bit of discussion around inline tree building.   ( linked here 
http://markmail.org/message/7zigjknpakugflje ).  For practice I am converting the freely available C v2 ANTLR .g  and I came over a rule that has me stuck...

It keeps the internal symbol-table by adding part of a tree into the symbol table along with the C symbol (in this case enum).

Normally a v2 rewrite would look like below (from stdcparser.g)

enumerator[String enumName]
        :       i:ID                { symbolTable.add(  i.getText(),
                                                        #(   null,
                                                            #[LITERAL_enum, "enum"],
                                                            #[ ID, enumName]
                                                         )
                                                     );
                                    }
                (ASSIGN constExpr)?
        ;

#( ) under v2 calls ASTFactory.create(), but under v3 it just appears to pass straight through into the Java target?  

This is true even when re-written, as I guessed it should be below.

enumerator[String enumName]  
        :       i=ID         { symbolTable.add(  $i.text,
                                                        ^(   NULL,
                                                            ^(LITERAL_enum),
                                                            ^(ID $enumName..text)
                                                         )
                                                     );
                                    }
                (ASSIGN constExpr)?
        ;

The only thing I came up with is "rewriting" the rule, and creating a dummy rule inside and using $dummy.tree inside the action.

Any thoughts from the more experienced community?

Kind Regards,

Luc


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


More information about the antlr-interest mailing list