summaryrefslogtreecommitdiffstats
path: root/src/front/symbol.py
blob: 879403faf543d6ff28021d789fe3e7aab6161cf8 (plain) (blame)
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
class SymbolClass(object):
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

    def __repr__(self):
        return "<SymbolClass: %s>" % self

SymbolClass.CONST = SymbolClass("CONST")
SymbolClass.VAR   = SymbolClass("VAR")
SymbolClass.FUNC  = SymbolClass("FUNC")

class SymbolType(object):
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

    def __repr__(self):
        return "<SymbolType: %s>" % self

SymbolType.INT  = SymbolType("INT")
SymbolType.BOOL = SymbolType("BOOL")

class Symbol(object):
    __slots__ = ['cls', 'type', 'value']

    def __init__(self, value, type = SymbolType.INT, cls = SymbolClass.VAR):
        self.value = value
        self.type = type
        self.cls = cls