本文整理汇总了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()