Tree2Dot

Motivation

ANTLR, ANother Tool for Language Recognition, is a Java-based tree parser generator that allows users to define grammars and AST-parsers for specific languages. For debugging purposes it is possible to print ANTLR's representation of a AST in a string representation. For my purposes, this string representation soon got too big, so I decided to us ANTLR to write a parser for these strings and translate them into a DOT file that can be used to visualize the tree with Graphviz.

Prerequisites

You need the following tools for running Tree2Dot:

Using Tree2Dot

First of all generate the Tree2Dot parser using ANTLR:
$> java org.antlr.Tool Tree.g

Thereafter, you can use Tree2Dot with the output of ANTLR's tree.toString() method. A sample session can be viewed here:

This results in a sample output graph such as this:

Download

ANTLR grammar:

Tree.g

Tree2Dot python tool:

Tree2Dot