For the summer I am working through the nand2tetris course and am currently on the chapter 6 project (building an assembler). My choice for Python was motivated by the presence of the lovely dictionary. Problem is I cannot seem to work/create/access one correctly. In following the API for the chapter they recommend 3 distinct classes for the assembler, namely the Parser
class, SymbolTable
class, and Code
class.
The machine we have built has the following specified mem. locations already dedicated to predefined symbols.
So with the following PreAllocated memory locations:
SP - (hex 00000, bin 0000000000000000)
LCL - (hex 00001, bin 0000000000000001)
ARG - (hex 00002, bin 0000000000000010)
THIS - (hex 00003, bin 0000000000000011)
THAT - (hex 0004, bin 0000000000000100)
R0-R15 - (hex 000[0-15], bin 000000000000[0-1111])
SCREEN - (hex 04000, bin 0100000000000000)
KBD - (hex 06000, bin 0110000000000000)
I wanted to create the class in such a manner that the table itself is the object, and when instantiated naturally assigns these {'key': value}
pairs.
symbolTable.py
:
class symbolTable(object):
def __init__(self):
self.table = {'SP': 0000000000000000, 'LCL': 0000000000000001,
'ARG': 0000000000000010, 'THIS': 0000000000000011,
'THAT': 0000000000000100, 'R0': 0000000000000000,
'R1': 0000000000000001, 'R2': 0000000000000010,
'R3': 0000000000000011, 'R4': 000000000000100,
'R5': 0000000000000101, 'R6': 0000000000000110,
'R7': 0000000000000111, 'R8': 0000000000001000,
'R9': 0000000000001001, 'R10': 0000000000001010,
'R11': 0000000000001011, 'R12': 0000000000001100,
'R13': 0000000000001101, 'R14': 0000000000001110,
'R15': 0000000000001111, 'SCREEN': 0100000000000000,
'KBD': 0110000000000000};
Before moving on with the additions of the attributes I am trying to simply create this thing. Yet, when I pull up and run my main file, main.py
:
__author__ = 'Cheech Wife'
import symbolTable
newTable = symbolTable.SymbolTable()
print newTable
I get nothing:
C:\Python27\python.exe "C:/Users/Cheech Wife/Desktop/cs 271/Assembler_ch6/symbolTable.py"
Process finished with exit code 0
From what I have read, the file separation should not be the issue, and having worked with C++ I am a huge fan of the compartmentalization and would like the files to remain distinct. So what am I doing wrong?
is my error in trying to make the object of my class the dictionary itself? Am I doing something wrong when I attempt to instantiate the thing?