[antlr-interest] tree walker executes method call twice?
Jim Idle
jimi at temporal-wave.com
Wed Aug 19 12:10:12 PDT 2009
Safiye Celik wrote:
> Hi,
> How do you create DoubleWalk1.jpg tree? I wanna display my tree as
> yours which is more understandable for a human, but I cannot get such
> a tree. I use JTree component constructed from a DefaultTreeModel
> component, and the tree I get is as in the attachment, which is in
> expandable folder format and not readable enough. And I could not find
> any component in Java to display a tree as yours. I would be glad if
> you share your way. Thanks.
Search the past posting for how to generate a dot (www.graphviz.org)
specification from the AST and then run dot:
// Use the ANLTR built in dot generator
//
DOTTreeGenerator gen = new DOTTreeGenerator();
// Which we can cause to generate the DOT specification
// with the input file name suffixed with .dot. You
can then use
// the graphviz tools or zgrviewer (Java) to view
the grahpical
// version of the dot file.
//
source = source.substring(0, source.length()-3);
String outputName = source + "dot";
System.out.println(" Producing AST dot (graphviz)
file");
// It produces a jguru string template.
//
StringTemplate st = gen.toDOT(t, new
CommonTreeAdaptor(), _treeST, _edgeST);
// Create the output file and write the dot spec to it
//
FileWriter outputStream = new FileWriter(outputName);
outputStream.write(st.toString());
outputStream.close();
// Invoke dot to generate a .png file
//
System.out.println(" Producing png graphic for
tree");
pStart = System.currentTimeMillis();
Process proc = Runtime.getRuntime().exec("dot -Tpng
-o" + source + "png " + outputName);
proc.waitFor();
stop = System.currentTimeMillis();
System.out.println(" PNG graphic produced in "
+ (stop - pStart) + "ms.");
Jim
More information about the antlr-interest
mailing list