本文整理汇总了Python中SymbolTable.SymbolTable.addEntry方法的典型用法代码示例。如果您正苦于以下问题:Python SymbolTable.addEntry方法的具体用法?Python SymbolTable.addEntry怎么用?Python SymbolTable.addEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.addEntry方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import addEntry [as 别名]
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()
示例2: symboltabletests
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import addEntry [as 别名]
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"))
示例3: Parser
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import addEntry [as 别名]
"""
import sys
from Parser import Parser
import Code
from SymbolTable import SymbolTable
asmFilename = sys.argv[1]
# This goes through the file and adds the address for each label to the symbol table.
parser = Parser(asmFilename)
symbolTable = SymbolTable()
romAddress = 0
while parser.hasMoreCommands():
parser.advance()
if parser.commandType() == "L_COMMAND":
symbolTable.addEntry(parser.symbol(), romAddress)
else:
romAddress += 1
# This opens the file that will be written to.
hackFilename = asmFilename[:-3] + "hack"
hackFile = open(hackFilename, "w")
# This writes the translated code to the hack file.
parser.restart()
ramAddress = 16
while parser.hasMoreCommands():
parser.advance()
commandType = parser.commandType()
if commandType == "C_COMMAND":
hackFile.write("111" + Code.comp(parser.comp()) + Code.dest(parser.dest()) + Code.jump(parser.jump()) + "\n")
示例4: SymbolTable
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import addEntry [as 别名]
offset = 0
symbols = SymbolTable()
while p.hasMoreCommands():
t = p.commandType()
if t == "A_COMMAND":
offset += 1
s = p.symbol()
elif t == "C_COMMAND":
offset += 1
elif t == "L_COMMAND":
s = p.symbol()
if symbols.contains(s):
raise SyntaxError("multiple declarations of %s" % s)
else:
symbols.addEntry(s, offset)
else:
raise Error
p.advance()
p.reset()
output = []
variable_offset = itertools.count(16)
def new_variable(name):
symbols.addEntry(name, variable_offset.__next__())
while p.hasMoreCommands():
t = p.commandType()
示例5: SymbolTable
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import addEntry [as 别名]
from SymbolTable import SymbolTable
tab = SymbolTable()
tab.addEntry("testSymbol", 32767)
print "=====Testing SymbolTable"
if not tab.contains("testSymbol"):
print "SymbolTable.contains should return true"
if tab.getAddress("testSymbol") != "111111111111111":
print "SymbolTable.getAddress did not return correct value"
tab.addVariable("testVar")
if tab.getAddress("testVar") != "000000000010000":
print "SymbolTable.getAddress did not return correct value for var"
print "Done testing SymbolTable====="
示例6: exit
# 需要导入模块: from SymbolTable import SymbolTable [as 别名]
# 或者: from SymbolTable.SymbolTable import addEntry [as 别名]
print outPath + ": file could not be opened"
exit(1)
#init parser and symbolTable
parser = Parser(inPath)
symbolTable = SymbolTable()
#pass 0
i = 0
while parser.hasMoreCommands():
parser.advance()
if parser.commandType() == "L":
symbolTable.addEntry(parser.symbol(), i)
else:
i += 1
#pass 1
parser.reset()
while parser.hasMoreCommands():
parser.advance()
type = parser.commandType()
if type == "A":
sym = parser.symbol()
#sym is a constant
if ord(sym[0]) >= ord("0") and ord(sym[0]) <= ord("9"):