Exemplo n.º 1
0
 /* Performs semantic analysis on the program. Returns null if any of the phases
  * fails. If a fatal error is encountered in one phase, analysis will not continue,
  * but internal recovery is attempted within each phase of analysis.
  *
  * The phases are:
  * 1. Building a symbol table. This checks that there are no name clashes in
  *    type declarations or cyclic dependencies. Cyclic dependencies are treated
  *    as fatal errors and will lead to type and reference checks not being run.
  *    If name clashes are found, the compiler will not even proceed to check
  *    cyclic dependencies. This is also treated as a fatal error.
  * 2. Semantic checks. This phase checks first the validity of name references
  *    and then performs type checks on all expressions. References to possibly
  *    uninitialized variables are also detected.
  *
  * All errors are logged in the error log.
  */
 private bool ConstructSymbolTableAndCheckProgram(Program abstractSyntaxTree)
 {
     var symbolTableSuccess = new SymbolTableBuilder(abstractSyntaxTree, _errorLog).BuildSymbolTable();
     bool semanticCheckSuccess = true;
     if (symbolTableSuccess != SymbolTableBuilder.ExitCode.FatalError)
     {
         semanticCheckSuccess = new SemanticsChecker(abstractSyntaxTree, _errorLog).RunCheck();
     }
     return (symbolTableSuccess == SymbolTableBuilder.ExitCode.Success) && semanticCheckSuccess;
 }
Exemplo n.º 2
0
 public TypeChecker(SemanticsChecker parent)
 {
     _parent = parent;
     _returnTypes = new Stack<IType>();
     _checkOK = true;
 }