[antlr-interest] ASTFrame for V3

Cameron Palmer cameron.palmer at gmail.com
Sat May 26 09:04:26 PDT 2007


I got the following code fragment from Ter's book, and am using it to
generate the GraphViz DOT files. You should buy the book. :)

import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.stringtemplate.*;

public class Main {
	public static void main(String args[]) {		
		try {
			ANTLRInputStream input = new ANTLRInputStream(System.in);
			SDFLexer lexer = new SDFLexer(input);
			CommonTokenStream tokens = new CommonTokenStream(lexer);
			SDFParser parser = new SDFParser(tokens);
			SDFParser.program_return r = parser.program();
			CommonTree t = (CommonTree)r.getTree();

			if( args.length>0 && args[0].equals("-dot") ) {
				DOTTreeGenerator gen = new DOTTreeGenerator();
				StringTemplate st = gen.toDOT(t);
				System.out.println(st);
			} else {
				System.out.println(t.toStringTree());
			}
			CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
			nodes.setTokenStream(tokens);
			SDFWalker walker = new SDFWalker(nodes);
			walker.program();
			
		} catch(Exception e) { System.err.println("Exception: "+e); }
	}
}


On 5/25/07, Terence Parr <parrt at cs.usfca.edu> wrote:
> there is a DOT generation method on the CommonTree I think.
> Ter
> On May 25, 2007, at 1:40 AM, Ivo Jimenez wrote:
>
> > Is there a way of graphically displaying an AST in V3.
> >
> > Thanks :)
>
>


More information about the antlr-interest mailing list