Class TypeChecker
- java.lang.Object
-
- compilation.analysis.semantic.TypeChecker
-
public final class TypeChecker extends java.lang.ObjectThe TypeChecker class is responsible for performing semantic analysis on a ParseTree, discovering whether or not the data types used together within statements are compatible with one another.It creates an AnnotatedParseTree that mirrors the same structure of the ParseTree generated by the Parser, except Statements are given extra information concerning the data types used (the word 'Annotated' being used to refer to this). During this stage any attempt to perform operations on values of incompatible data types are identified and reported as an error.
The ParseTree produced by the Parser 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 whether or not operations being performed on unary values or between binary values are valid, based on their data type(s).
- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description TypeChecker(Parser parser, ErrorHandler errorHandler, SymbolTable symbolTable)Constructs a TypeChecker object initialised with ParseTree from the Parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AnnotatedParseTreegetAnnotatedParseTree()Returns an AnnotatedParseTree object generated from the Parser.
-
-
-
Constructor Detail
-
TypeChecker
public TypeChecker(Parser parser, ErrorHandler errorHandler, SymbolTable symbolTable)
Constructs a TypeChecker object initialised with ParseTree from the Parser.The TypeChecker adds any errors to the errorHandler, and adds any declared Symbols to the symbolTable.
- Parameters:
parser- The Parser used to generate the ParseTreeerrorHandler- The ErrorHandler to store any errors that occursymbolTable- The SymbolTable to store any Symbols that are declared
-
-
Method Detail
-
getAnnotatedParseTree
public AnnotatedParseTree getAnnotatedParseTree() throws Exception
Returns an AnnotatedParseTree object generated from the Parser.The Statements contained within the ParseTree retrieved from the Parser are annotated with information regarding the data types used, and then returned in the form of an AnnotatedParseTree.
- Returns:
- An AnnotatedParseTree containing the root AnnotatedStatement
- Throws:
Exception- If the ParseTree contains a StatementType that has not been defined
-
-