def main(filename): # get the root of the parse tree of the input file parseTreeRoot = parseFile(filename) # the errorHandler which will group all of the errors errorHandler = ErrorHandler(filename) try: # create an AST an attach it to a listener so the listener can fill in the tree abstractSyntaxTree = buildAST(parseTreeRoot) firstPassDecoration(abstractSyntaxTree) # create a symbol table and symbol table filler, fill in the table and check if everything is declared before it is used in the c file symbolTable = SymbolTable() scopeCheck(abstractSyntaxTree, errorHandler, symbolTable) # do the type checking typeCheck(abstractSyntaxTree, errorHandler) output(str(abstractSyntaxTree)) output(str(symbolTable)) # generate code if not errorHandler.errorCount(): generateCode(abstractSyntaxTree, symbolTable) except Exception as e: ex_type, ex, tb = sys.exc_info() traceback.print_exception(ex_type, ex, tb) if errorHandler.errorCount() or errorHandler.warningCount(): print(str(errorHandler.errorCount()) + " error" + ("s" if errorHandler.errorCount() != 1 else "")) print(str(errorHandler.warningCount()) + " warning" + ("s" if errorHandler.warningCount() != 1 else "")) errorHandler.printErrors()