[antlr-interest] C Runtime Multiple Serial Tree Walkers - What can be freed when?

Jim Idle jimi at temporal-wave.com
Tue Jan 18 15:15:15 PST 2011


The rewrites do not [always] duplicate the nodes, they change the pointers
and so on. Hence you need to keep all the stuff around. It is not as
inefficient as you think and it is keeping pointers to the input source
and so on too, so you must keep it all around until you have finished
using it. Just tear it all down and rerun it when ready to do the codegen.
It won't take anytime at all to do that.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Karim Chichakly
> Sent: Tuesday, January 18, 2011 3:07 PM
> To: antlr-interest at antlr.org interest
> Subject: [antlr-interest] C Runtime Multiple Serial Tree Walkers - What
> can be freed when?
>
> I am using the C runtime.  I have a lexer and a parser.  Then I run a
> constant expression reduction tree walker, which rewrites some nodes
> (rewrite = false).  Then I run a semantic analysis tree walker, which
> also rewrites some nodes (rewrite = false).  Then, at a much later time
> determined by the user, I run a code generation tree walker.  I have to
> keep the final tree (from the semantic analyzer) around as long as the
> program is running, which could be hours.
>
> The C runtime example that does something similar, polydiff, keeps all
> of the separate node streams and all of the intermediate trees around
> until it no longer needs the final tree.  The Java version keeps
> overwriting the nodes variable (which holds the node stream), so
> presumably that is getting freed before the start of each tree walker
> pass.  But also it keeps all the intermediate trees.
>
> If I try to free the first tree generated by the parser after running
> the first tree walker (which gives me a different tree), the program
> crashes on the free.  If I try to free the node stream, the tree
> becomes invalid and I crash the next time I try to access it.
>
> I don't honestly have to keep all intermediate tree results and node
> streams around forever, do I?  What can I safely get rid of and when?
>
> Thanks,
>
> Karim
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list