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


Python SymbolTable.printSymbolTables方法代码示例

本文整理汇总了Python中SymbolTable.SymbolTable.printSymbolTables方法的典型用法代码示例。如果您正苦于以下问题:Python SymbolTable.printSymbolTables方法的具体用法?Python SymbolTable.printSymbolTables怎么用?Python SymbolTable.printSymbolTables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SymbolTable.SymbolTable的用法示例。


在下文中一共展示了SymbolTable.printSymbolTables方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CompliationEngine

# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import printSymbolTables [as 别名]
class CompliationEngine(object):
    """
    Effects the actual compilation output. Gets its input from a
    JackTokenizer and emits its parsed structure into an output file/stream
    """

    MAP = {"<": "&lt;", ">": "&gt;", '"': "&quot;", "&": "&amp;"}

    def __init__(self, tokenizer, out_file_name):
        """
        Constructor
        """
        self._tokenizer = tokenizer
        self._vm_writer = VMWriter(out_file_name)
        self._class_name = None
        self._symbol_table = SymbolTable()
        self._counter = 0
        self._subroutine_name = None

    def Compile(self):
        token = str(self._tokenizer.next_token())
        if token == "class":
            self.CompileClass(token)

    def CompileClass(self, token):
        """
        takes 'class' as token
        and end the compilation
        """
        self._class_name = self._tokenizer.next_token()  # got the class name
        str(self._tokenizer.next_token())  # '{'
        token = self._tokenizer.next_token()  # field declarations

        # For declaring Class Level Variable

        while token in ["field", "static"]:
            token = self.CompileClassVarDec(token)

        # Class Methods
        while token in ["function", "method", "constructor"]:
            token = self.CompileSubroutine(token)

        self._vm_writer.writer_close()
        self._symbol_table.printSymbolTables()

    def CompileSubroutine(self, token):
        """
        Takes any among 'function', 'method', 'constructor'
        and return token after end of subroutine '}' 
        or simple next subroutine token
        """
        function_modifier = token

        str(self._tokenizer.next_token())  # return type
        function_name = str(self._tokenizer.next_token())  # name of function

        self._subroutine_name = function_name

        self._symbol_table.startSubRoutine(function_name)
        if function_modifier == "method":
            self._symbol_table.define(["this", self._class_name, "argument"])

        str(self._tokenizer.next_token())  # '('

        token = str(self._tokenizer.next_token())  # 'arguments'

        while token != ")":
            token = self.CompileParamList(token)

        str(self._tokenizer.next_token())  # '{'
        token = str(self._tokenizer.next_token())  # Statements or '}'

        while token == "var":
            token = self.CompileVarDec(token)

        local_variables = self._symbol_table.varCount("local")

        # Writing Function VM
        self._vm_writer.write_subroutine(self._class_name, function_name, local_variables)
        if function_name == "new":
            no_of_fields = self._symbol_table.varCount("field")
            self._vm_writer.write_push("constant", no_of_fields)
            self._vm_writer.write_call("Memory", "alloc", 1)
            self._vm_writer.write_pop("pointer", 0)
        if function_modifier == "method":
            self._vm_writer.write_push("argument", 0)
            self._vm_writer.write_pop("pointer", 0)
        """temp_buffer = ""
        while local_variables > 0:
            temp_buffer += 'push constant 0\n'
            local_variables -= 1
        
        self._out_file_object.write(temp_buffer)
        self._out_file_object.flush()"""

        while token != "}":
            token = self.CompileStatements(token)

        token = str(self._tokenizer.next_token())  # next subroutine
        return token
#.........这里部分代码省略.........
开发者ID:saikumarm4,项目名称:Nand2Tetris,代码行数:103,代码来源:Compilation.py


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