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


Python SymbolTable.SymbolTable类代码示例

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


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

示例1: main

def main():
	"output file is the file where output will be written to"
	filename = sys.argv[1].split('.')[0]
	outputfile = open( filename + ".hack", "a" )

	"input file is the file where input will come from"
	inputfile = Parser( sys.argv[1] )

	lines = inputfile.commandLines()

	for line in lines:
		if( ParserComd( line ).commandType() == 'A_command' ):
			symbol_line = ParserComd( line ).symbol( )
			symbol_a = SymbolTable( )
			symbol_a.addEntry( symbol_line )
			f = symbol_a.GetAddress( symbol_line )
			outputfile.write( f )
			outputfile.write( '\n' )

		elif( ParserComd( line ).commandType() == 'C_command_a' or ParserComd( line ).commandType() == 'C_command_b'):
			dest_line = ParserComd( line ).dest()
			comp_line = ParserComd( line ).comp()
			jump_line = ParserComd( line ).jump()
			cbinary = Code( dest_line, comp_line, jump_line ).cinstruction()
			outputfile.write( cbinary )
			outputfile.write( '\n' )
		elif( ParserComd( line ).commandType() == 'L_command' ):
			outputfile.write( 'This line is going to delete\n' )

	outputfile.close()
开发者ID:chenzhengchen200821109,项目名称:github-nand2tetries,代码行数:30,代码来源:main.py

示例2: symboltabletests

class symboltabletests(unittest.TestCase):

    def setUp(self):
        self.st = SymbolTable()

    def testContains(self):
        self.st.addEntry("loop", 100)
        self.assertTrue(self.st.contains("loop"))
        self.assertFalse(self.st.contains("bobby"))
开发者ID:dserver,项目名称:Nand2Tetris,代码行数:9,代码来源:testSymbolTable.py

示例3: first_pass

def first_pass(path):
    p = Parser(path)

    symbol_table = SymbolTable()
    n = 0
    while(p.hasMoreCommands()):
        command_type = p.commandType()
        if(command_type == CommandType.L):
            symbol_table.add_entry(p.symbol(), n)
        else:
            n += 1
        p.advance()
    return symbol_table
开发者ID:bendanon,项目名称:n2t-proj6,代码行数:13,代码来源:Main.py

示例4: visit_Fundef

 def visit_Fundef(self, node):
     node.Functions.putNewFun(node.id, node.type) 
     Functions = FunctionsTable(node.Functions, "Functions")
     Variables = SymbolTable(node.Variables, "Variables")
     node.argList.Functions = Functions
     node.argList.Variables = Variables
     listOfArguments = node.argList.accept(self)
     for element in listOfArguments:
         if element!= None:
             node.Functions.put(node.id, element[1])
             if Variables.put(element[0], element[1])==-1:
                 self.errors.append("In line "+ str(node.lineno) + ": variable "+ element.name + " was initialized")
     node.compoundInstr.Functions = Functions
     node.compoundInstr.Variables = Variables
     node.compoundInstr.accept(self)
开发者ID:xav9211,项目名称:Kompilatory,代码行数:15,代码来源:TypeChecker.py

示例5: setUp

    def setUp(self):
        self.assembler = Assembler()
        parser = Parser()
        self.symbolTable = SymbolTable()

        self.assembler.setSymbolTable(self.symbolTable)
        self.assembler.setParser(parser)
开发者ID:dserver,项目名称:Nand2Tetris,代码行数:7,代码来源:testAssemblerFinal.py

示例6: visit_FunDef

 def visit_FunDef(self,node):
     # print "visiting FunDef"
     self.symbolTable = SymbolTable(self.symbolTable,node.id.value)
     self.symbolTable.getParentScope().put(node.id.value,FunSymbol(node.typeOrId, node.id.value, map(lambda x: x.accept(self),node.argList.list)))
     node.compoundInstr.accept(self)
     self.symbolTable = self.symbolTable.getParentScope()
     return node.id.value
开发者ID:Ucash,项目名称:Interpreter,代码行数:7,代码来源:TypeChecker.py

示例7: visit_ClassDef

 def visit_ClassDef(self,node):
     # print "visiting ClassDef"
     self.symbolTable = SymbolTable(self.symbolTable if node.parentId == None else self.classTables[node.parentId.value], node.id.value)
     classSymbol = ClassSymbol(node.accessmodificator, node.id.value, node.parentId if node.parentId == None else node.parentId.accept(self),node.classcontent.accept(self))
     self.classTables[node.id.value]=self.symbolTable
     while self.symbolTable.parent!=None:
         self.symbolTable = self.symbolTable.getParentScope()
     self.symbolTable.put(node.id.value,classSymbol)
开发者ID:Ucash,项目名称:Interpreter,代码行数:8,代码来源:TypeChecker.py

示例8: __init__

 def __init__(self, inputFile, outputFile):
     self.tokenizer = JackTokenizer(inputFile)
     self.vmWriter = VMWriter(outputFile)
     self.symbolTable = SymbolTable()
     self.classname = ""
     self.CompileClass()
     self.whilecounter = 0
     self.ifcounter = 0
开发者ID:idan0610,项目名称:nand-project11,代码行数:8,代码来源:CompilationEngine.py

示例9: visit_Program

 def visit_Program(self,node):
     try:
         #print "visiting Program"
         self.symbolTable=SymbolTable(None,'main')
         node.declarations.accept(self)
         node.fundefs.accept(self)
         node.instructions.accept(self)
     except:
         self.error("could not continue parsing, correct errors first",0)
开发者ID:xorver,项目名称:Kompilatory,代码行数:9,代码来源:TypeChecker.py

示例10: __init__

 def __init__(self, tokenizer, outputFile, vmFile):
     from SymbolTable import SymbolTable
     from VMWriter import VMWriter
     self.tokenizer = tokenizer
     self.outputFile = outputFile
     self.symbolTable = SymbolTable()
     self.vmWriter = VMWriter(vmFile)
     self.labelNum = 0
     print(outputFile)
开发者ID:itzhak-razi,项目名称:Elements-of-Computing-Systems-Assignments,代码行数:9,代码来源:CompilationEngine.py

示例11: __init__

 def __init__(self,tokens,vmwriter):
     try:
         tokens[0].value
         tokens[0].type
     except:
         sys.exit("Parser did not take in a list of tokens!")
     self.tokens=tokens
     self.vmwriter=vmwriter
     self.symTable=SymbolTable()
开发者ID:hubbazoot,项目名称:ecs10,代码行数:9,代码来源:Parser.py

示例12: visit_CompoundInstruction

    def visit_CompoundInstruction(self, node):
        self.scope = SymbolTable(self.scope, "compound")

        for declaration in node.decls:
            declaration.accept(self)
        for instruction in node.instrs:
            instruction.accept(self)

        # Get the hell out of function scope, after its done
        self.scope = self.scope.parent
开发者ID:jswk,项目名称:tk,代码行数:10,代码来源:TypeChecker.py

示例13: __init__

 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
开发者ID:saikumarm4,项目名称:Nand2Tetris,代码行数:10,代码来源:Compilation.py

示例14: __init__

 def __init__(self, input_file, output_file):
     self.jack_tokenizer = JackTokenizer(input_file)
     self.symbol_table = SymbolTable()
     self.writer = VMWriter(output_file)
     self.class_name = ""
     self.subroutine_name = ""
     self.return_type = ""
     self.label_counter_if = 0
     self.label_counter_while = 0
     self.num_args_called_function = 0
     self.is_unary = False
     self.dic_arithmetic = {"+" : "add" , "-" : "sub", "*" : "call Math.multiply 2",
                            "/" : "call Math.divide 2", "&" : "and", "|" : "or", "<" : "lt", ">" : "gt", "=" : "eq"}
开发者ID:hadarfranco,项目名称:From-NAND-to-Tetris,代码行数:13,代码来源:CompilationEngine.py

示例15: __init__

    def __init__(self, input_file_path):
        self.output_file = open(input_file_path.replace('.asm', '.hack'), 'w')

        """
        The ROM address is the address of the current instruction written in the
        .hack file. The first instruction is 0, second is 1, etc. Label is not a instruction.
        """
        self.current_rom_address = ROM_BASE_ADRESS

        self.parser = Parser(input_file_path)
        self.symbol_table = SymbolTable()

        """
        The RAM address of the next free memory that a new variable
        should be at.
        """
        self.next_free_var_address = VARIABLES_BASE_ADDRESS
开发者ID:adirz,项目名称:sample-projects,代码行数:17,代码来源:Assembler.py


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