-
Notifications
You must be signed in to change notification settings - Fork 1
/
symbols.py
33 lines (22 loc) · 853 Bytes
/
symbols.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
from symtable import Symbol
class VariableSymbol(object):
def __init__(self, name, type, size):
self.name = name
self.type = type
self.size = size
class SymbolTable(object):
def __init__(self, parent, name): # parent scope and symbol table name
self.parent = parent
self.name = name
self.symbols = {}
self.scope = ["main"]
def put(self, name, symbol, size = None): # put variable symbol or fundef under <name> entry
self.symbols[name] = VariableSymbol(name, symbol, size)
def get(self, name): # get variable symbol or fundef from <name> entry
return self.symbols.get(name, None)
def getParentScope(self):
return self.scope[-1]
def pushScope(self, name):
self.scope.append(name)
def popScope(self):
self.scope.pop()