Newer
Older
zweic / sources / zweic / AnalyzerTest.scala
@glproj03 glproj03 on 20 Dec 2005 1016 bytes new files part 4
/*  zweic -- a compiler for Zwei
 *
 *  Stephane Micheloud & LAMP
 *
 *  $Id$
 */

package zweic;


/** A small test class for the semantic analyzer of zweic; it reads
 *  in a file and prints out the abstract syntax tree. If the program
 *  is erroneous, the compiler will print a corresponding error message
 *  instead.
 *
 *  usage: scala zweic.AnalyzerTest <file.zwei>
 */
object AnalyzerTest {
  import java.io.{FileInputStream, IOException};

  def main(args: Array[String]): Unit = {
    if (args.length != 1) {
      Console.println("usage: scala zweic.AnalyzerTest <file.zwei>");
      System.exit(1)
    }
    try {
      val in = new FileInputStream(args(0));
      val tree = new Parser(in).parse;
      in.close();
      if (Report.errors > 0)
        System.err.println(Report.errors + " errors found.");
      else
        new Analyzer().analyzeProgram(tree);
      System.exit(if (Report.errors > 0) 1 else 0);
    }
    catch {
      case e: IOException => Report.fail(e.getMessage())
    }
  }

}