/* * Simple front-end for an ANTLR lexer/parser that dumps the AST * textually and displays it graphically. Good for debugging AST * construction rules. * * Behrooz Badii, Miguel Maldonado, and Stephen A. Edwards */ import java.io.*; import antlr.CommonAST; import antlr.collections.AST; import antlr.debug.misc.ASTFrame; public class Main { public static void main(String args[]) { try { DataInputStream input = new DataInputStream(System.in); // Create the lexer and parser and feed them the input SimpLexer lexer = new SimpLexer(input); SimpParser parser = new SimpParser(lexer); parser.file(); // "file" is the main rule in the parser // Get the AST from the parser CommonAST parseTree = (CommonAST)parser.getAST(); // Print the AST in a human-readable format System.out.println(parseTree.toStringList()); // Open a window in which the AST is displayed graphically ASTFrame frame = new ASTFrame("AST from the Simp parser", parseTree); frame.setVisible(true); } catch(Exception e) { System.err.println("Exception: "+e); } } }