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

Jogchem de Groot r.e.j.degroot at student.utwente.nl
Tue Jun 15 10:14:54 PDT 2004


Hello,

I dont think that is the solution as the current factory is "good 
enough". The new AST
nodes are created from the old nodes with the ASTFactory.create(AST tr) 
method
which has the following code:

    public AST create(AST tr) {
        if (tr == null) return null;            // create(null) == null
        AST t = create(tr.getType());
                if ( t!=null ) {
                        t.initialize(tr);
                }
        return t;
    }

As you can see it calls an initialize method on the newly allocated AST 
which allows it
to initialize itself from an old AST. (My initialize() method copies all 
the data members
associated with an AST over to itself).

The problem is the timeline in which this happens, given the rule i 
showed before:

#(b:blah) { b.setData(data); }

Very roughly, this will first match the 'blah' node, after this matched 
it will create
a new new AST node for the transformed AST. It will use the older AST 
node (b)
for this. And only after that, it will call setData() on the old b AST 
node. In psuedocode:

<First>
b = match(blah)
AST new_b = ASTFactory.create(b);
astFactory.addASTChild(currentAST, new_b);
...
b.setData(data);
<End>

I hope this gives some more insight on the problem.

Regards,
    Jogchem


Adrian Tineo wrote:

>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
>  
>



 
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