[antlr-interest] Problem with keeping data associated with AST nodes in antlr transform mode

Adrian Tineo tineo at ac.uma.es
Tue Jun 15 09:28:06 PDT 2004


I think you need to have your own factory subclassed from ASTFactory 
overriding the create() and make() methods. Then in your main class you would 
do:

parser.setASTNodeClass(package.Class);

Check http://www.antlr.org/doc/trees.html#_bb11

Adrian Tineo


El Martes, 15 de Junio de 2004 14:30, Jogchem de Groot escribió:
> Good afternoon,
>
> I'm working on a translater using ANTLR which uses several
> transformation phases (implemented
> as tree walkers). Frequently i'd like to associate data with AST nodes
> in the transformation phases
> which can be used in later phases.
>
> The problem is that data i associate with some AST does keep associated
> with the equivalent AST nodes
> in the resulting transformed AST. I looked a little into the problem at
> it seems to me that ANTLR
> generates AST generation code which constructs the new AST just after
> the nodes have been matched.
> So even though you can create your own initialize() methode in your own
> AST node class, which can copy
> all extended data fields from an existing AST node in a new AST node,
> this wont have any effect as
> updates done the old AST node will not be reflected in the new AST node.
>
> For example:
>
> #(b:blah) { b.setData(data); }
>
> This will associate 'data' with the old AST node (b), but not with the
> newly generated equivalent AST node for
> the transformed tree, because that AST node has been constructed before
> the 'b.setData(..)' code has executed.
>
> Is there anyway to get around this problem?
>
> Thanks in advance!
>
> Regards,
>     Jogchem
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list