當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。