At 05:24 10/11/2008, Chris Sekszczynska wrote:
 >There, I like to achieve something like this:
 >
 >              -> ^(PROGRAM ^(GLOBALS {«return the element of
 >$SymbolTable::newGlobals»}) sourceElement*)
 >
 >The GLOBALS-subtree should look like ^(GLOBALS i x y) when "i",
 >"x" and "y" are the token-names in my "newGlobals" ArrayList.

All the functions that ANTLR itself uses to 
construct ASTs are available to your code.

This is air code, so might need a bit of 
tweaking, but it ought to work:

program
scope SymbolTable;
@init {
   // initialize the scope for this block
   $SymbolTable::newGlobals = new ArrayList<String>();
   CommonTree globalTree = null;
}
@after {
   System.out.println("Number of globals: " + 
$SymbolTable::newGlobals.size());
}
   : sourceElement*
     {
       globalTree = (CommonTree)adaptor.becomeRoot(
           adaptor.create(GLOBALS, "GLOBALS"), adaptor.nil());
       foreach (String name in $SymbolTable::newGlobals)
       {
         adaptor.addChild(globalTree, adaptor.create(ID, name));
       }
     }
            -> ^(PROGRAM {globalTree} sourceElement*)
         ;


List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to