[antlr-interest] Parse trees visualization tools?

guillot.bernard at hit.com.hk guillot.bernard at hit.com.hk
Mon Aug 19 22:15:18 PDT 2002


Elias,

	A good Visualization of the parsed tree is built in ANTLR. It is
called ASTFrame.

You can Easily View And Debug Your Parsed Tree with it.

Hope This can Help You.

Bernard Guillot


Here is an Extract of some code I use (taken from an example in the antlr
code)

/* 
	Code 1 Easy to view What the Tree Viewer will look like

// This is a simple Tree To look how simple it can look
// Create the tree nodes
ASTFactory factory = new ASTFactory();
CommonAST r = (CommonAST)factory.create(0, "ROOT");
r.addChild((CommonAST)factory.create(0, "C1"));
r.addChild((CommonAST)factory.create(0, "C2"));
r.addChild((CommonAST)factory.create(0, "C3"));

ASTFrame frame = new ASTFrame("AST JTree Example", r);
frame.setVisible(true);

// End of Simple Test

*/


/*
	Code 2 A Real Example
*/

			
String Filename filename="Myfile";
File file = new File ("/pathtomyfile/" + filename);
InputStream inStream = new InputStream(file);

MyLexer lexer = new MyLexer(inStream);
lexer.setFilename(filename);

// Create a parser that reads from the scanner
MyParser parser = new MyParser(lexer);
parser.setFilename(filename);

showTree=1;	// Change or get it as a parameter when calling this class

// do something with the tree

if ( showTree ) {
				
	System.out.println("Will Show the AST Tree");

	// Real Example of Tree Viewing
	
      ((CommonAST)t).setVerboseStringConversion(true,
parser.getTokenNames());
      ASTFactory factory = new ASTFactory();
      AST r = factory.create(0,"AST ROOT");
      r.setFirstChild(parser.getAST());
      final ASTFrame frame = new ASTFrame("Java AST", r);
      frame.setVisible(true);
      frame.addWindowListener(
	      new WindowAdapter() {
      		public void windowClosing (WindowEvent e) {
            		frame.setVisible(false); // hide the Frame
				frame.dispose();
	                  System.exit(0);
      	      }
      	}
	);

}


-----Original Message-----
From: Elias Biris [mailto:user_sofia at biris.freeserve.co.uk] 
Sent: 20 August, 2002 1:54 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Parse trees visualization tools?


Hi,

I am looking for any tools that allow generation/visualization of graphical
representations of parse trees based on antlr or yacc grammars. Does anyone
know of any such tool?

Thanks




 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



CONFIDENTIALITY: This communication and any attachment(s) is intended solely
for the person or organisation to which it is addressed and it may be
confidential. If you are not the intended recipient, employee or agent
responsible for delivering the message to the intended recipient you must
not copy, disclose, distribute or take any action in reliance on it. If you
have received this communication in error, please notify the sender
immediately and destroy the original.  If this communication has been
received by email please reply and highlight the error to the sender and
delete the original.  Thank you.

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list