本文整理汇总了Python中SymbolTable.SymbolTable.isDefined方法的典型用法代码示例。如果您正苦于以下问题:Python SymbolTable.isDefined方法的具体用法?Python SymbolTable.isDefined怎么用?Python SymbolTable.isDefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.isDefined方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import isDefined [as 别名]
#.........这里部分代码省略.........
self.tokenizer.advance()
self.compileSubroutineCall()
self.vmWriter.writePop("temp", 0) #This pops and ignores the returned value
self.printToken() #Print ';'
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
self.indentLevel -= 1
self.writeFormatted("</doStatement>")
def compileLet(self):
from SymbolTable import SymbolTable
from VMWriter import VMWriter
self.writeFormatted("<letStatement>")
self.indentLevel += 1
isArray = False
if self.tokenizer.keyWord() != "let":
raise Exception("Let keyword expected")
self.printToken() #Should print "let"
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
self.printToken() #Should print varname
varName = self.tokenizer.identifier()
self.writeVarInfo(self.tokenizer.identifier(), True)
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
self.printToken() #Should print '[' or '='
print("compileLet - [ or = " + self.tokenizer.currentToken)
if self.tokenizer.currentToken == "[":
isArray = True
self.tokenizer.advance()
if self.symbolTable.isDefined(varName):
varKind = self.symbolTable.kindOf(varName)
self.vmWriter.writePush(varKind, self.symbolTable.indexOf(varName))
self.compileExpression()
self.printToken() #Should print ']'
self.vmWriter.writeArithmetic("add")
segment = "that"
index = 0
else:
raise Exception("Symbol " + varName + " is not defined")
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
self.printToken() #Should print '='
else:
#If it goes down this path this is just a regular variable not an array
varKind = self.symbolTable.kindOf(varName)
segment = varKind
index = self.symbolTable.indexOf(varName)
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
print("compileLet - after equals " + self.tokenizer.currentToken)
self.compileExpression()
if isArray:
self.vmWriter.writePop("temp", 0)
self.vmWriter.writePop("pointer", VMWriter.THAT_POINTER)
self.vmWriter.writePush("temp", 0)
self.vmWriter.writePop(segment, index)