本文整理汇总了Python中SymbolTable.SymbolTable.getDirect方法的典型用法代码示例。如果您正苦于以下问题:Python SymbolTable.getDirect方法的具体用法?Python SymbolTable.getDirect怎么用?Python SymbolTable.getDirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.getDirect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TypeChecker
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import getDirect [as 别名]
#.........这里部分代码省略.........
return value.type
else:
print("Undefined variable {0} at {1}:{2}".format(node.name, node.pos[0], node.pos[1]))
return None
def visit_If(self, node):
condition_type = node.condition.accept(self)
if condition_type != 'int':
print("Condition must evaluate to integer at {0}:{1}".format(node.condition.pos[0], node.condition.pos[1]))
node.block_if.accept(self)
if node.block_else != None:
node.block_else.accept(self)
def visit_While(self, node):
condition_type = node.condition.accept(self)
if condition_type != 'int':
print("Condition must evaluate to integer at {0}:{1}".format(node.condition.pos[0], node.condition.pos[1]))
old_breakable = self.breakable
self.breakable = True
node.body.accept(self)
self.breakable = old_breakable
def visit_Repeat(self, node):
condition_type = node.condition.accept(self)
if condition_type != 'int':
print("Condition must evaluate to integer at {0}:{1}".format(node.condition.pos[0], node.condition.pos[1]))
old_breakable = self.breakable
self.breakable = True
node.body.accept(self)
self.breakable = old_breakable
def visit_Fundef(self, node):
symbol = self.scope.getDirect(node.name)
if symbol is None:
self.scope.put(node.name, node)
else:
print("Symbol {0} already defined at {1}:{2}. First defined at {3}:{4}".format(
node.name, node.pos[0], node.pos[1], symbol.pos[0], symbol.pos[1]))
# Create new scope for function
self.scope = SymbolTable(self.scope, node.name)
# Leave information about return type of the function
self.return_type = node.return_type
self.returned = False
for argument in node.arguments:
argument.accept(self)
node.body.accept(self)
if not self.returned:
print("No return statement found in function {0} defined at {1}:{2}".format(node.name, node.pos[0], node.pos[1]))
# Clear information about return type
self.return_type = None
self.returned = False
# Get the hell out of function scope, after its done
self.scope = self.scope.parent
def visit_Arg(self, node):
self.scope.put(node.id, node)
return node.type
def visit_Declaration(self, node):
for init in node.inits:
init.type = node.type
defined_var = self.scope.getDirect(init.name.name)
if defined_var is not None: