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 Coding dependent on the CompilerMode:
	-  CompilerMode = viaJavaSource:
		- 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.
	-  CompilerMode = directClassFiles:
		- Traverse the syntax tree generating ClassFile code.
		- Create executable .jar of program.
		- Execute .jar file.
	-  CompilerMode = simulaClassLoader:
		- Traverse the syntax tree generate and load ClassFile code.
		- Run the loaded program

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
  • 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() throws IOException
      Do Compile
      Throws:
      IOException - when it fails
    • doExecuteJarFile

      private void doExecuteJarFile(String jarFile, Vector<String> arg) throws IOException
      Execute JarFile.
      Parameters:
      jarFile - a jarFile
      arg - the arguments
      Throws:
      IOException - if something went wrong.
    • doCallJavaCompiler

      private void doCallJavaCompiler() throws IOException
      Call Java compiler 'javac'
      Throws:
      IOException - if something went wrong.
    • 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)
      Call Java command line compiler.
      Parameters:
      classPath - the classPath
      Returns:
      return value from the Java compiler
    • doByteCodeEngineering

      private void doByteCodeEngineering() throws IOException
      Possible doByteCodeEngineering reintroducing labels and goto.
      Throws:
      IOException - if something went wrong.
    • listGeneratedClassFiles

      private void listGeneratedClassFiles()
      Debug utility: listGeneratedClassFiles.
    • fileSummary

      private void fileSummary()
      File Summary
    • printSummary

      private void printSummary()
      Print summary at program end.