How do I display ASTs graphically
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.