LARA

package minijava
 
import parser.Parser
import analyzer.Analyzer
import analyzer.TypeChecker
 
class Compiler
    extends Reporter
    with Parser
    with Analyzer
    with TypeChecker {
  import java.io.{FileInputStream,IOException,ByteArrayInputStream}
 
  def compile(fileName: String): Unit = {
    import parser.Trees._
    import analyzer.Symbols._
 
    // Parsing
    var parsedTree: Option[Tree] = None
    try {
      val in = new FileInputStream(fileName)
      parsedTree = Some(parseInputStream(in))
      in.close()
    } catch {
      case e: IOException => fatalError(e.getMessage)
    }
    terminateIfErrors
 
    val mainProg: Program = parsedTree match {
      case Some(p:Program) => p
      case _ => fatalError("Main program expected from parser.")
    }
 
    // Name analysis
    val global: GlobalScope = analyzeSymbols(mainProg)
    terminateIfErrors
 
    // Type checking
    typeCheck(mainProg, global)
    terminateIfErrors
 
    println(TreePrinter.withSymbolIDs(mainProg))
 
    ;
  }
}