本文整理匯總了Python中SymbolTable.SymbolTable.addVariable方法的典型用法代碼示例。如果您正苦於以下問題:Python SymbolTable.addVariable方法的具體用法?Python SymbolTable.addVariable怎麽用?Python SymbolTable.addVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SymbolTable.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.addVariable方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: SymbolTable
# 需要導入模塊: from SymbolTable import SymbolTable [as 別名]
# 或者: from SymbolTable.SymbolTable import addVariable [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====="
示例2: ord
# 需要導入模塊: from SymbolTable import SymbolTable [as 別名]
# 或者: from SymbolTable.SymbolTable import addVariable [as 別名]
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"):
outFile.write("0" + Code.decimalConstantToBinaryString(sym) + "\n")
#sym is in table
elif symbolTable.contains(sym):
outFile.write("0" + symbolTable.getAddress(sym) + "\n")
#sym is a new var
else:
symbolTable.addVariable(sym)
outFile.write("0" + symbolTable.getAddress(sym) + "\n")
elif type == "C":
d = Code.dest(parser.dest())
c = Code.comp(parser.comp())
j = Code.jump(parser.jump())
outFile.write("111" + c + d + j + "\n")
outFile.close()