当前位置: 首页>>代码示例>>Python>>正文


Python SymbolTable.getIncludingParents方法代码示例

本文整理汇总了Python中SymbolTable.SymbolTable.getIncludingParents方法的典型用法代码示例。如果您正苦于以下问题:Python SymbolTable.getIncludingParents方法的具体用法?Python SymbolTable.getIncludingParents怎么用?Python SymbolTable.getIncludingParents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SymbolTable.SymbolTable的用法示例。


在下文中一共展示了SymbolTable.getIncludingParents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TypeChecker

# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import getIncludingParents [as 别名]

#.........这里部分代码省略.........
        node.instructions.accept(self)
        node.condition.accept(self)
    
    def visit_ReturnInstr(self,node):
        # print "visiting Return"
        node.expression.accept(self) #todo check somehow
    
    def visit_CompoundInstr(self,node):
        # print "visiting CompoundInstr"
        #self.symbolTable = SymbolTable(self.symbolTable,'compoundInstr')
        node.declarations.accept(self)
        node.instructions.accept(self)
        #self.symbolTable = self.symbolTable.getParentScope()
    
    def visit_Condition(self,node):
        # print "visiting Condition"
        if node.expression.accept(self) not in ('int'):
            self.error("condition must be of int type",node.line)
    
    def visit_Integer(self,node):
        # print "visiting Integer"
        return 'int'
    
    def visit_Float(self,node):
        # print "visiting Float"
        return 'float'
    
    def visit_String(self,node):
        # print "visiting String"
        return 'string'
    
    def visit_Id(self,node):
        # print "visiting Id"
        if self.symbolTable.getIncludingParents(node.value):
            return self.symbolTable.getIncludingParents(node.value)
        self.error("undefined symbol: "+node.value,node.line)
    
    def visit_ParExpr(self,node):
        # print "visiting ParExpr"
        return node.expression.accept(self)   
        
    def visit_BinExpr(self,node):
        operator = node.operator
        first = node.first.accept(self)
        second = node.second.accept(self)            
            
        # print "visiting BinExpr"
        #print first
        #print operator
        #print second
        try:
            return self.ttype[operator][first][second]
        except:
            self.error("cannot compute operation: " +operator+",on arguments: "+first+", "+second,node.first.line)
            
          
    def visit_FunExpr(self,node):
        # print "visiting FunExpr"
        funSymbol = node.access.accept(self)
        for i in range(len(node.expressionList.list)):
            try:
                baseArgType = funSymbol.argList[i]
                givenArgType = node.expressionList.list[i].accept(self)
                self.ttype['f'][baseArgType][givenArgType]
            except:
                self.error("bad argument in funcall",node.line)
开发者ID:Ucash,项目名称:Interpreter,代码行数:70,代码来源:TypeChecker.py

示例2: TypeChecker

# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import getIncludingParents [as 别名]

#.........这里部分代码省略.........
            except:
                self.error("cannot initialize symbol of type: "+declType+", with expression of type: "+type,id.value)
            self.symbolTable.put(id.value,type)
    
    def visit_Inits(self,node):
        #print "visiting Inits"
        toReturn=[]
        for element in node.list:
            toReturn.append(element.accept(self))
        return toReturn
    
    def visit_Init(self,node):
        #print "visiting Init"
        return [node.expression.accept(self),node.id]
    
    def visit_Instructions(self,node):
        #print "visiting Instructions"
        self.symbolTable = SymbolTable(self.symbolTable,'instructions')
        for element in node.list :
            element.accept(self)
        self.symbolTable = self.symbolTable.getParentScope()
            
    def visit_PrintInstr(self,node):
        #print "visiting PrintInstr"
        if node.expression.accept(self) not in ['string','int','float']:
            self.error("cannot print expression of that type",node.line)
        
    def visit_LabeledInstr(self,node):
        #print "visiting LabeledInstr"
        node.instruction.accept(self)
    
    def visit_Assignment(self,node):
        #print "visiting Assignment"
        if self.symbolTable.getIncludingParents(node.id.value) == None:
            self.error("unknown symbol name: "+id.value,id.line)
        try:
            idType = node.id.accept(self)
            exprType = node.expression.accept(self)
            self.ttype['f'][idType][exprType]
        except:
            self.error("cannot assign "+exprType+" to "+idType,node.id.line)
            
    
    def visit_ChoiceInstr(self,node):
        #print "visiting ChoiceInstr"
        node.condition.accept(self)
        node.instruction.accept(self)
        node.elseInstruction.accept(self)
        
    def visit_Break(self,node):
        #print "visiting Break"
        pass
    
    def visit_Continue(self,node):
        #print "visiting Continue"
        pass
    
    def visit_WhileInstr(self,node):
        #print "visiting While"
        node.condition.accept(self)
        self.symbolTable = SymbolTable(self.symbolTable,'while')
        node.instruction.accept(self)
        self.symbolTable = self.symbolTable.getParentScope()
    
    def visit_RepeatInstr(self,node):
        #print "visiting Repeat"
开发者ID:xorver,项目名称:Kompilatory,代码行数:70,代码来源:TypeChecker.py


注:本文中的SymbolTable.SymbolTable.getIncludingParents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。