Module Simula

Class SimulaCompiler

java.lang.Object
simula.compiler.SimulaCompiler

public final class SimulaCompiler extends Object
The Simula Compiler.

The compiler consists of the following steps:

  • Initiate global variables.
  • Do Parsing: Read source file through the scanner building program syntax tree.
  • Do Checking: Traverse the syntax tree performing semantic checking.
  • Do JavaCoding: Traverse the syntax tree generating .java code.
  • Call Java Compiler to generate .class files.
  • Do ByteCodeEngineering updating .class files.
  • Create executable .jar of program.
  • Execute .jar file.

Link to GitHub: Source File.

Author:
Øystein Myhre Andersen
  • Field Details

    • reader

      private final Reader reader
      The Reader in case of SimulaEditor.
    • programModule

      private ProgramModule programModule
      The ProgramModule.
    • outputJarFile

      private File outputJarFile
      The output .jar file
    • mainEntry

      private String mainEntry
      Main entry name.
  • Constructor Details

    • SimulaCompiler

      public SimulaCompiler(String inputFileName)
      Create a new SimulaCompiler.
      Parameters:
      inputFileName - the source file name
    • SimulaCompiler

      public SimulaCompiler(String inputFileName, Reader reader)
      Create a new SimulaCompiler.
      Parameters:
      inputFileName - the source file name
      reader - Reader in case of SimulaEditor
  • Method Details

    • list

      private void list(File dir)
      List temp class file directory tree
      Parameters:
      dir - tempClassFileDir
    • list

      private void list(String indent, File dir)
      List a directory tree.
      Parameters:
      indent - the indentation
      dir - the directory
    • deleteTempFiles

      private void deleteTempFiles(File dir)
      Delete temporary .class files.
      Parameters:
      dir - temporary .class directory
    • doCompile

      public void doCompile()
      Do Compile
    • callJavaSystemCompiler

      private int callJavaSystemCompiler(JavaCompiler compiler, String classPath) throws IOException
      Call Java system compiler
      Parameters:
      compiler - the Java compiler
      classPath - the classPath
      Returns:
      return value from the Java compiler
      Throws:
      IOException - if something went wrong
    • callJavacCompiler

      private int callJavacCompiler(String classPath) throws IOException
      Call Java command line compiler.
      Parameters:
      classPath - the classPath
      Returns:
      return value from the Java compiler
      Throws:
      IOException - if something went wrong
    • createJarFile

      private String createJarFile(ProgramModule program) throws IOException
      Create .jar file.
      Parameters:
      program - the ProgramModule
      Returns:
      .jar file name
      Throws:
      IOException - if something went wrong
    • add

      private void add(JarOutputStream target, File source, int pathSize) throws IOException
      Add directory or a file to a JarOutputStream.
      Parameters:
      target - the JarOutputStream
      source - source file or directory
      pathSize - the path size
      Throws:
      IOException - if something went wrong
    • fileSummary

      private void fileSummary()
      File Summary
    • printSummary

      private void printSummary()
      Print summary at program end.
    • listJarFile

      private static void listJarFile(File file)
      List .jar file
      Parameters:
      file - the .jar file
    • doListClassFile

      public static void doListClassFile(String classFileName)
      Print a .class file listing.
      Parameters:
      classFileName - the .class file name
    • execute

      private static int execute(Vector<String> cmd) throws IOException
      Execute OS Command
      Parameters:
      cmd - command vector
      Returns:
      return value from the OS
      Throws:
      IOException - if something went wrong
    • execute

      public static int execute(String... cmdarray) throws IOException
      Execute an OS command
      Parameters:
      cmdarray - command array
      Returns:
      exit value
      Throws:
      IOException - if an I/O error occurs