Dashboard > ANTLR 3 > ... > FAQ - Tree construction > How do I display ASTs graphically
  ANTLR 3 Log In | Sign Up   View a printable version of the current page.  
  How do I display ASTs graphically
Added by Terence Parr, last edited by Lucian Adrian Grijincu on Apr 02, 2008  (view change)
Labels: 

Instead of using t.toStringTree(), you can ask ANTLR to generate DOT/graphviz format:

DOTTreeGenerator gen = new DOTTreeGenerator();
StringTemplate st = gen.toDOT(t);
System.out.println(st);

To display in a Swing window (Java target), use this:

CommonTree t = (CommonTree) r.getTree();
ASTFrame af = new ASTFrame("Tree", t);
af.setVisible(true);

where you need the attached code from Jörg Werner.

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.1 Build:#806 May 06, 2007) - Bug/feature request - Contact Administrators