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

Karim Chichakly kchichakly at iseesystems.com
Tue Jan 18 15:07:28 PST 2011


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


More information about the antlr-interest mailing list