home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / compilers / p5 / Main.java < prev    next >
Text File  |  2005-11-01  |  2KB  |  64 lines

  1. // --------------------------------  Main  --------------------------------
  2. //
  3. // Compiler Project 5 - PCAT Compiler Main
  4. //
  5. // This class is never instantiated.  It includes the "main" method
  6. // to exercise components of the PCAT compiler.
  7. //
  8. // Harry Porter -- 01/26/03
  9. //                 02/07/03 -- Modified for Project 4
  10. //                 02/12/03 -- Modified for Project 5
  11. //
  12.  
  13. import java.io.*;
  14.  
  15. class Main {
  16.  
  17.     //
  18.     // Static Fields
  19.     //
  20.     static int errorCount = 0;         // How many errors, so far
  21.     static Ast.Body ast = null;        // The Abstract Syntax Tree
  22.     static Parser parser = null;       // The parser
  23.     static Checker checker = null;     // The checker
  24.  
  25.  
  26.     //
  27.     // Main ()
  28.     //
  29.     // Create a parser, parse a PCAT source file, and print the AST.
  30.     //
  31.     public static void main (String [] args) {
  32.         try {
  33.  
  34.             // Parse the source...
  35.             System.err.println ("Parsing Source Code...");
  36.             parser = new Parser (args);
  37.             ast = parser.parseProgram ();
  38.  
  39.             // Check the AST...
  40.             System.err.println ("Semantic Error Checking...");
  41.             checker = new Checker ();
  42.             checker.checkAst (ast);
  43.  
  44.             // Print the full AST...
  45.             PrintAst.printAst (ast);
  46.  
  47.             // Pretty-print the AST...
  48.             PrettyPrint.prettyPrintAst (ast);
  49.  
  50.         } catch (LogicError e) {
  51.             e.printStackTrace ();
  52.         } catch (FatalError e) {
  53.             if (e.getMessage () != null) {
  54.                 System.err.println (e.getMessage ());
  55.             }
  56.         }
  57.         if (errorCount > 0) {
  58.             System.err.println (errorCount + " error(s) were detected!");
  59.             System.exit (1);
  60.         }
  61.     }
  62.  
  63. }
  64.