My goal is to create the AST in a way that I can quickly access information 
about *important* child nodes - for example if I had:

proc : PROCEDURE ident formalPartOpt body -> ^(PROCEDURE_DECL ident 
formalPartOpt body);

I would like this to create an AST node that would have the identifier and 
parameters easily accessible, with something like ASTProc.getIdent() or 
ASTProc.getParams();

I've found three ways of doing this, all seem like they blend the code and 
grammar too much:

1. Creating heterogeneous tree nodes like on this page: 
http://www.antlr.org/wiki/display/ANTLR3/Tree+construction - and passing the 
identifier and formalPartOpt trees as parameters

2. Using custom AST nodes, and whenever a child is added to a custom ASTProc 
node, testing if it is of a type I care about - i.e., if child.getType() == 
Lexer.IDENT, store that as the name of the procedure.

3. Wait until the information is requested from the node and traverse the tree 
to find the name or parameters.

Are there other ways of doing this that are more efficient/decouple the AST 
creation from the grammar a little better?

Thanks in advance,
Jared

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

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

Reply via email to