本文整理匯總了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)
示例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"