forked from kcecireyes/JIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjit_symboltable.py
41 lines (32 loc) · 1.21 KB
/
jit_symboltable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class SymbolTable:
#Common base class for all STs
def __init__(self):
self.table = [] # an empty list of dictionaries
def addRecord(self,record):
self.table.append(record)
def searchRecord(self,var_name):
for i in range(0,len(self.table)):
if self.table[i]['name'] == var_name: #search by name succeeds
return i
return -1 #search fails
def updateRecord(self,i,record):
self.table[i] = record
def getRecord(self,var_name):
j = self.searchRecord(var_name)
return self.table[j]
def getRecordType(self, i):
record_type = self.table[i]['type']
return record_type
def getRecordExpType(self, i):
record_exp_type = self.table[i]['exp_type']
return record_exp_type
def printST(self):
ret = ""
for record in (self.table):
ret = ret + str(record) + '\n'
return ret
def copyRecords(self, to_ST):
for i in range(0,len(self.table)):
to_ST.addRecord(self.table[i])
# TODO: error handling (what if the table to copy from has no records, etc)
return 1 # all records copied