Class Evaluator
- java.lang.Object
-
- compilation.generation.Evaluator
-
public final class Evaluator extends java.lang.ObjectThe Evaluator class is responsible for evaluating Expressions and calculating their results, so that the the final value(s) of the input code can be produced.It creates a List of Objects that hold the final values generated by the compilation process. However, only values which were printed by the user are added to this list. During this stage no errors are reported, though exceptions can occur if it comes across an undefined Statement or Expression.
The AnnotatedParseTree produced by the TypeChecker is retrieved, with its contents being parsed recursively to mirror the structure of the tree. The Expressions contained within each individual statement are inspected in an attempt to discover the data types being used and the operation being performed, which is then executed and the result calculated using Java code. This result may be used as part of a large Expression or Statement, such as in a conditional or loop, or returned by the Evaluator as an element in a List object.
- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description Evaluator(TypeChecker typeChecker, SymbolTable symbolTable, boolean replMode)Constructs an Evaluator object initialised with the AnnotatedParseTree from the TypeChecker.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object[]getEvaluation()Returns a primitive array of Objects generated from the TypeChecker
-
-
-
Constructor Detail
-
Evaluator
public Evaluator(TypeChecker typeChecker, SymbolTable symbolTable, boolean replMode)
Constructs an Evaluator object initialised with the AnnotatedParseTree from the TypeChecker.The Evaluator adds any Symbols to the symbolTable, and initialises a new ArrayList to store output objects.
If REPL mode is true, the Evaluator will return all calculated values. This should typically be a single value, as the during this mode only a single Expression is parsed at a time.
- Parameters:
typeChecker- The TypeChecker used to generate the AnnotatedParseTreesymbolTable- The SymbolTable to store any Symbols that are declaredreplMode- The boolean indicating the Parser should run in REPL mode
-
-
Method Detail
-
getEvaluation
public java.lang.Object[] getEvaluation() throws ExceptionReturns a primitive array of Objects generated from the TypeCheckerThe AnnotatedStatements contained within the AnnotatedParseTree retrieved from the TypeChecker have their contained Expressions evaluated, calculating their results and appended to an array, which is then returned.
- Returns:
- A primitive array of Objects containing the result(s)
- Throws:
Exception- If the AnnotatedParseTree contains an AnnotatedStatementType that has not been defined
-
-