[antlr-interest] Custom AST nodes - attempt #2
Bill Andersen
bill.andersen at mac.com
Thu Jul 22 12:26:57 PDT 2010
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
More information about the antlr-interest
mailing list