/** * Copyright (c) 2000, Fidel Viegas (viegasfh@hotmail.com). * All rights reserved. * * Please read the LICENSE file for license information. * * This is a driver program for the smallPascal compiler. This file is similar * to the one provided in the calculator example found in the thesis * report of SableCC. */ package org.sablecc.pascal.compiler; import org.sablecc.pascal.node.*; import org.sablecc.pascal.tool.*; import org.sablecc.pascal.semantic.*; import org.sablecc.pascal.code.*; import java.io.*; public class Main { public static void main(String[] args) { System.out.println(Version.banner()); System.out.println("This software comes with ABSOLUTELY NO WARRANTY."); System.out.println("Please read the LICENSE file for license information."); System.out.println(); // check the number of arguments if (args.length != 1 || !args[0].endsWith(".pas")) { System.out.println("Usage: "); System.out.println(" java SmallPascal.compiler.Main filename.pas"); System.exit(0); } try { // parse the program and assign the generated AST to node root System.out.println("Parsing " + args[0] + "..."); Node root = TreeBuilder.getNode( new PushbackReader( new BufferedReader( new FileReader(args[0])), 1024)); // process semantic analysis System.out.println("Checking identifiers..."); root.apply(new SemanticAnalyser()); // process code generation System.out.println("Generating " + args[0].substring(0, args[0].length() - 4) + ".j"); root.apply(new CodeGenerator(args[0])); // finished compilation System.out.println("done."); } catch(Exception exc) { System.out.println(exc); // output the exception } } }