[antlr-interest] AST Construction

Sinan sinan.karasu at boeing.com
Wed Feb 27 09:07:52 PST 2002

anuragag_iitk wrote:
> Hi,
>   I want to use antlr to construct an AST in which nodes of user
> defined node types will be associated with non-terminals in the the
> grammer.How do I about it? The documentation that I have seen tells
> how to associate user-defined node types with Tokens only and not with
> rules or non-terminals.Please give me some reference or some examples
> on this
> -- Anurag

 You can just create a synthetic "Token" root for your non-terminals ,
and then traverse 
the non-terminals.


 rule : x y z { ##=#([MYROOT],##);

 and then in tree walker:

 #(m:MYROOT   { for(i=0;i<100000) {myrule(m,i);})

myrule[int i]: #(MYROOT x y z);

So basically it boils down to tagging an AST with an artifical root.



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list