import java.io.*;

import antlr.CommonAST;
import antlr.collections.AST;
import antlr.debug.misc.ASTFrame;
import antlr.DumpASTVisitor;
import antlr.Token;

public class GECLrunner
{
    public static void main(String[] args)
    {
        for (int i=0; i<args.length; i++)
        {
			try
			{
				String programName = args[i];
				DataInputStream dis = null;
				if (programName.equals("-")) {
					dis = new DataInputStream( System.in );
				}   
				else {
					dis = new DataInputStream(new FileInputStream(programName));
				}
				GECLLexer lexer = new GECLLexer ( dis );
				GECLParser parser = new GECLParser(lexer);       
			
				parser.program();
			
				CommonAST tree = (CommonAST)parser.getAST();
				System.out.println(tree.toStringTree());
				
				GECLWalker walker = new GECLWalker();
				walker.program(tree);

				// Open a window in which the AST is displayed graphically
				ASTFrame frame = new ASTFrame("AST from the Simp parser", tree);
				frame.setVisible(true);				
    		}
			catch (Exception e)
			{
				System.err.println ( "exception: " + e);
				e.printStackTrace();
			}
			
        }
    }
}