Package compilation

Class Compiler


  • public final class Compiler
    extends java.lang.Object
    The Compiler class is used to run the full compilation process on a String of code.

    It takes a String as input and runs the entire compilation process on it, producing a SourceOutput object which contains the result. Each Compiler object contains its own SymbolTable instance, and initialises with REPL mode set to false by default.

    Since:
    1.0
    • Constructor Summary

      Constructors 
      Constructor Description
      Compiler()
      Constructs a Compiler object initialised with an empty SymbolTable.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      SourceOutput compile​(java.lang.String sourceText)
      Compiles a String of code, generating a SourceOutput object containing the result.
      void printParseTree()
      Print the ParseTree generated from the latest compilation.
      void printSymbolTable()
      Print the SymbolTable generated from the latest compilation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Compiler

        public Compiler()
        Constructs a Compiler object initialised with an empty SymbolTable.

        The Compiler always starts with REPL mode disabled.

    • Method Detail

      • compile

        public SourceOutput compile​(java.lang.String sourceText)
        Compiles a String of code, generating a SourceOutput object containing the result.

        The String passed to this method is subjected to the full compilation process: - Lexical analysis (performed by the Lexer class) - Syntax analysis (performed by the Parser class) - Semantic analysis (performed by the TypeChecker class) - Evaluation (performed by the Evaluator class) The SourceOutput contains both the evaluated result and List of Errors and Exceptions that may have occurred.

        Parameters:
        sourceText - The String of code to be compiled
        Returns:
        A SourceOutput object containing the result
      • printParseTree

        public void printParseTree()
        Print the ParseTree generated from the latest compilation.

        This may only be run after the 'compile' method has been called.

      • printSymbolTable

        public void printSymbolTable()
        Print the SymbolTable generated from the latest compilation.

        This may only be run after the 'compile' method has been called.