本文整理匯總了Python中SymbolTable.SymbolTable.stringKindOf方法的典型用法代碼示例。如果您正苦於以下問題:Python SymbolTable.stringKindOf方法的具體用法?Python SymbolTable.stringKindOf怎麽用?Python SymbolTable.stringKindOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SymbolTable.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.stringKindOf方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from SymbolTable import SymbolTable [as 別名]
# 或者: from SymbolTable.SymbolTable import stringKindOf [as 別名]
#.........這裏部分代碼省略.........
self.compileExpression()
self.numExpressions += 1
if self.tokenizer.tokenType == JackTokenizer.SYMBOL and self.tokenizer.symbol() == ",":
self.printToken() #print ','
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
self.indentLevel -= 1
self.writeFormatted("</expressionList>")
def compileSubroutineCall(self):
from JackTokenizer import JackTokenizer
from VMWriter import VMWriter
self.printToken() #Should print either the subroutine name or the class/object the
#subroutine is a member of
firstToken = self.tokenizer.currentToken
secondToken = ""
isClassOrObj = False
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
self.printToken() #Should print '.' or '('
if self.tokenizer.tokenType == JackTokenizer.SYMBOL and self.tokenizer.symbol() == ".":
isClassOrObj = True
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
self.printToken() #Should print subroutine name
secondToken = self.tokenizer.currentToken
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
self.printToken() #Should print opening '('
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
#If the subroutine is a method call we must first push the object before
#pushing the rest of the arguments
if secondToken != "" and self.symbolTable.isDefined(firstToken):
self.vmWriter.writePush(self.symbolTable.kindOf(firstToken), self.symbolTable.indexOf(firstToken))
if secondToken == "":
self.vmWriter.writePush("pointer", VMWriter.THIS_POINTER)
self.compileExpressionList()
self.printToken() #Should print ')'
if self.tokenizer.hasMoreTokens():
self.tokenizer.advance()
if secondToken != "":
if self.symbolTable.isDefined(firstToken):
callName = self.symbolTable.typeOf(firstToken) + "." + secondToken
self.numExpressions += 1
else:
callName = firstToken + "." + secondToken
else:
self.numExpressions += 1
callName = self.className + "." + firstToken
self.vmWriter.writeCall(callName, self.numExpressions)
if isClassOrObj and self.symbolTable.isDefined(firstToken):
self.writeVarInfo(firstToken, True) #Writing information about an object
elif isClassOrObj:
self.writeClassOrSubInfo("class", True) #Writing information about a class
self.writeClassOrSubInfo("subroutine", True)
def printToken(self):
from JackTokenizer import JackTokenizer
if self.tokenizer.tokenType == JackTokenizer.KEYWORD:
self.writeFormatted("<keyword>" + self.tokenizer.keyWord() + "</keyword>")
elif self.tokenizer.tokenType == JackTokenizer.SYMBOL:
self.writeFormatted("<symbol>" + self.tokenizer.symbol() + "</symbol>")
elif self.tokenizer.tokenType == JackTokenizer.IDENTIFIER:
self.writeFormatted("<identifier>" + self.tokenizer.identifier() + "</identifier>")
elif self.tokenizer.tokenType == JackTokenizer.INT_CONST:
self.writeFormatted("<integerConstant>" + self.tokenizer.intVal() + "</integerConstant>")
elif self.tokenizer.tokenType == JackTokenizer.STRING_CONST:
self.writeFormatted("<stringConstant>" + self.tokenizer.stringVal() + "</stringConstant>")
def writeFormatted(self, string):
self.outputFile.write(" " * self.indentLevel + string + "\n")
def writeVarInfo(self, varName, inUse):
from SymbolTable import SymbolTable
self.writeFormatted("<IdentifierInfo>")
self.indentLevel += 1
self.writeFormatted("<type>" + self.symbolTable.typeOf(varName) + "</type>")
self.writeFormatted("<kind>" + self.symbolTable.stringKindOf(varName) + "</kind>")
self.writeFormatted("<index>" + str(self.symbolTable.indexOf(varName)) + "</index>")
self.writeFormatted("<inUse>" + str(inUse) + "</inUse>")
self.indentLevel -= 1
self.writeFormatted("</IdentifierInfo>")
def writeClassOrSubInfo(self, kind, inUse):
self.writeFormatted("<IdentifierInfo>")
self.indentLevel += 1
self.writeFormatted("<kind>" + kind + "</kind>")
self.writeFormatted("<inUse>" + str(inUse) + "</inUse>")
self.indentLevel -= 1
self.writeFormatted("</IdentifierInfo>")