[antlr-interest] ASTFrame for V3

Joerg.Werner at qimonda.com Joerg.Werner at qimonda.com
Sat May 26 10:39:25 PDT 2007


Hi,

This is a straightforward port of the ASTFrame from ANTLR 2.7.7.

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

Have fun,

Jörg
-- 
Dr. Jörg Werner (韦尔讷)
Qimonda AG 
Memory Products Division
QAG PD PT TPE C
Am Campeon 1-12
D-85579 Neubiberg
email: joerg.werner at qimonda.com
Tel:  +49 89 60088-2231
Fax:  +49 89 60088-442231

Chairman of the Supervisory Board/Aufsichtsratsvorsitzender: Peter J. Fischl
Management Board/Vorstand: Kin Wah Loh (Chairman/Vorsitzender), Dr. Michael Majerus, Thomas J. Seifert
Register Court/Registergericht: München HRB 152545, Seat/Sitz: München


-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Cameron Palmer
Sent: Saturday, May 26, 2007 6:04 PM
To: ivojimenez at gmail.com
Cc: ANTR Interest
Subject: Re: [antlr-interest] ASTFrame for V3

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 :)
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ASTtoTreeModelAdapter.java
Type: application/octet-stream
Size: 2390 bytes
Desc: ASTtoTreeModelAdapter.java
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070526/34f4422f/attachment-0002.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ASTFrame.java
Type: application/octet-stream
Size: 1078 bytes
Desc: ASTFrame.java
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070526/34f4422f/attachment-0003.obj 


More information about the antlr-interest mailing list