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