-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolTable.py
More file actions
27 lines (22 loc) · 825 Bytes
/
SymbolTable.py
File metadata and controls
27 lines (22 loc) · 825 Bytes
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
from tabulate import tabulate
class Symbol_Table:
def __init__(self):
self.table = []
def __str__(self):
table_list = [symbol.values() for symbol in self.table]
return tabulate(table_list, headers=['ID', 'SYMBOL NAME', 'ATTRIBUTE'], tablefmt='grid')
def __repr__(self):
return self.table
def add_item(self, symbol_name, attribute):
#check if identifier already exists
if attribute == 'IDENTIFIER':
for symbol in self.table:
if symbol['symbol_name'] == symbol_name:
return symbol['id']
symbol = {
'id': str(len(self.table)+1),
'symbol_name': symbol_name,
'attribute': attribute
}
self.table.append(symbol)
return symbol['id']