[antlr-interest] manual AST construction: what am I doing wro ng?

Tiller, Michael (M.M.) mtiller at ford.com
Mon Jun 16 07:58:43 PDT 2003


I wanted to point something out about this response...

> -----Original Message-----
> From: Ric Klaren [mailto:klaren at cs.utwente.nl]
> Subject: Re: [antlr-interest] manual AST construction: what am I doing wrong?
> 
> On Sun, Jun 15, 2003 at 01:26:35PM +0200, Jorge Scandaliaris wrote:
> > 	How can I generate for a rule a single AST node, using manual
> > tree construction?
> 
> In a nutshell:
> 
> myrule ! : st:SOME_TOKEN
> { ## = #([MY_IMAG_AST_NODE, st->getText()]);
>   ##->setSomeAttrib( sumthin );
> }
> ;

I think you need to be careful here.  As I pointed out in a question posted to this list (but never responded to), this does not work in certain cases (at least I couldn't get it to work).  The idea of having a line like:

##->setSomeAttribu(sumthin);

is to invoke a method on the custom AST node.  BUT, ANTLR will not generate an appropriate initializeASTFactory in some cases (see my previous note titled "Simple Question") and this would then fail.

I'm not saying there is anything wrong with Ric's response, just that it should come with some caveats about making sure that the "#([My_IMAG_AST_NODE...])" construct is truly generating the appropriate node type.

Jorge seems to be using a single AST type so this wouldn't appear trigger the issue I reported, but without a complete example of his grammar, you never know.

--
Mike

 

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




More information about the antlr-interest mailing list