示例#1
0
    def exitFunc_decl(self, ctx:LittleExprParser.Func_declContext):
        self.symbolTable.pop()
        identifier = ctx.identifier().getText()
        returnType = ctx.any_type().getText()
        functDeclNode = ASTFunctDecl(identifier, self.localNum-1, self.paramNum-1)

        if ctx.func_body() is not None and ctx.func_body().getText():
            if ctx.func_body().stmt_list() is not None and ctx.func_body().stmt_list().getText():
                functDeclNode.StmtListNode = self.ASTStack.pop()

        # print(functDeclNode.printInOrder())
        # functCode = functDeclNode.generateCode()#.replace("LINK", "LINK {0} {1}".format(self.localNum-1, self.paramNum-1))
        self.paramNum  = 1
        self.localNum  = 1
        AST.tempRegNum = 1

        if returnType == "FLOAT":
            self.functReturns[identifier] = NODETYPE.FLOATLITERAL
        elif returnType == "INT":
            self.functReturns[identifier] = NODETYPE.INTLITERAL

        self.functNodeList.append(functDeclNode)

        # print(functDeclNode.printInOrder())
        # functOptimizer = Optimizer(functCode)
        # functCode = functOptimizer.optimize()
        # self.allCode += functCode


        return
示例#2
0
 def enterFunc_decl(self, ctx:LittleExprParser.Func_declContext):
    self.printSymbolTable.append("\nSymbol table {0}\r".format(ctx.getChild(2).getText()))
    self.symbolTable.append({})
    pass