本文整理汇总了Python中SymbolTable.SymbolTable.searchScope方法的典型用法代码示例。如果您正苦于以下问题:Python SymbolTable.searchScope方法的具体用法?Python SymbolTable.searchScope怎么用?Python SymbolTable.searchScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.searchScope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import searchScope [as 别名]
#.........这里部分代码省略.........
self.getNext()
if self.tokenizer.getToken() == ')':
break
self.getNext() # ','
def compileStatements(self): # (letStatement | ifStatement | whileStatement | doStatement | returnStatement)*
"""Compiles a sequence of statements,
not including the enclosing "{}"."""
token = self.tokenizer.getToken()
while token in ["let", "if", "while", "do", "return"]:
if token == 'let':
self.compileLet()
elif token == 'if':
self.compileIf()
elif token == 'while':
self.compileWhile()
elif token == 'do':
self.compileDo()
elif token == 'return':
self.compileReturn()
token = self.tokenizer.getToken()
def compileSubroutineCall(self, name, printIdentifier=True):
# subroutineName '(' expressionList ') ' | ( className | varName) '.' subroutineName '(' expressionList ') '
var = None
nArgs = 0
if printIdentifier:
# subroutineName | ( className | varName)
self.getNext()
var = self.classTable.searchScope(name)
if self.tokenizer.getToken() == '.':
if var:
# push <this>
self.writer.writePush(var[0], var[1])
nArgs += 1
className = var[2] # Use the type instead of the variable name
else:
className = name
self.getNext()
subroutineName = self.tokenizer.getToken()
self.getNext()
else:
# push <this>
self.writer.writePush(Toolbox.POINTER, 0)
nArgs += 1
className = self.className
subroutineName = name
name = className + '.' + subroutineName
# '('
self.getNext()
nArgs += self.compileExpressionList()
self.writer.writeCall(name, nArgs)
# ')'
self.getNext()
def compileDo(self): # 'do' subroutineCall ';'
"""Compiles a do statement"""
# do
self.getNext()