[antlr-interest] Custom AST nodes - attempt #2

Terence Parr parrt at cs.usfca.edu
Thu Jul 22 13:34:49 PDT 2010


Hi Bill. try setting ASTLabelType in tree grammar.
T
On Jul 22, 2010, at 12:26 PM, Bill Andersen wrote:

> Hi Folks,
> 
> This is my second attempt at asking this question.  Hopefully it is clear.  If not, please let me know.
> 
> I'm interested in using a custom AST node class to carry type information.
> 
> I do not want to build a custom TreeAdaptor to determine node type based on token id because only a few AST nodes will have to be of the custom class.
> 
> Here's a sample production from the tree generating grammar.
> 
> rule
> 	: ... match something ...
> 	-> ^(NODE<CustomType>[param] ...)
> 	;
> 
> So far so good.  I know how to do this.  
> 
> Let's say CustomType looks like this
> 
> class CustomType extends CommonTree {
> 	public T param;
> 	public CustomType(int ttype, T param) { ... }
> 	public T getParam() { ... }
> 	...
> }
> 
> Now I have another grammar that consumes ASTs from the first grammar.  I want to do this:
> 
> rule
> 	: ^(NODE ...)
> 	  { ... do something with this information ... }
> 	;
> 
> So, what syntax do I need in the action to get a T-typed param value from this node?
> 
> Any help appreciated 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list