当前位置: 首页>>代码示例>>Python>>正文


Python SymbolTable.stringKindOf方法代码示例

本文整理汇总了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>")
开发者ID:itzhak-razi,项目名称:Elements-of-Computing-Systems-Assignments,代码行数:104,代码来源:CompilationEngine.py


注:本文中的SymbolTable.SymbolTable.stringKindOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。