summaryrefslogtreecommitdiffstats
path: root/Classes.py
blob: f144e77c2f3e04ccf4f532c59df92435a4482cf4 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
class KlassType:
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

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

KlassType.CONST    = KlassType("const")
KlassType.VAR      = KlassType("var")
KlassType.FUNCNAME = KlassTupe("function name")

class OperatorType:
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

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

OperatorType.EQ  = OperatorType("==")
OperatorType.NE  = OperatorType("!=")
OperatorType.GE  = OperatorType(">=")
OperatorType.LE  = OperatorType("<=")
OperatorType.GT  = OperatorType(">")
OperatorType.LT  = OperatorType("<")
OperatorType.ADD = OperatorType("+")
OperatorType.SUB = OperatorType("-")
OperatorType.MUL = OperatorType("*")
OperatorType.DIV = OperatorType("/")
OperatorType.MOD = OperatorType("%")
OperatorType.AND = OperatorType("&&")
OperatorType.OR  = OperatorType("||")

class TokenType:
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

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

TokenType.FUN      = TokenType("fun")
TokenType.IDENT    = TokenType("identifier")
TokenType.LBRAK    = TokenType("[")
TokenType.RBRAK    = TokenType("]")
TokenType.LPAREN   = TokenType("(")
TokenType.RPAREN   = TokenType(")")
TokenType.NEWLINE  = TokenType("newline")
TokenType.IF       = TokenType("if")
TokenType.TAB      = TokenType("tab")
TokenType.OPERATOR = TokenType("operator")
TokenType.NUMBER   = TokenType("number")
TokenType.RETURN   = TokenType("return")
TokenType.END      = TokenType("end")

class NonTerminalType:
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

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

NonTerminalType.FACTOR            = NonTerminalType("factor")
NonTerminalType.TERM              = NonTerminalType("term")
NonTerminalType.SIMPLE_EXPRESSION = NonTerminalType("simple_expression")
NonTerminalType.EXPRESSION        = NonTerminalType("expression")
NonTerminalType.IDENT_LIST        = NonTerminalType("ident_list")
NonTerminalType.EXPRESSION_LIST   = NonTerminalType("expression_list")
NonTerminalType.PROGRAM           = NonTerminalType("program")
NonTerminalType.FUNCTION          = NonTerminalType("function")
NonTerminalType.STATEMENT         = NonTerminalType("statement")
NonTerminalType.STATEMENTS        = NonTerminalType("statements")
NonTerminalType.IF_STATEMENT      = NonTerminalType("if_statement")
NonTerminalType.WHILE_STATEMENT   = NonTerminalType("while_statement")
NonTerminalType.RETURN_STATEMENT  = NonTerminalType("return_statement")
NonTerminalType.ASSIGNMENT        = NonTerminalType("assignment")
NonTerminalType.FUNCTION_CALL     = NonTerminalType("function_call")

class NonTerminal:
    # bsp: <FUNCTION, Zwischencode>
    def __init__(self,type,code=None):
        self.type = type
        self.code = code

class Token:
    # bsp: <identifier,0>
    def __init__(self,type,value=None):
        self.type = type
        self.value = value

class Tokenlist:
    tokenlist = []

    def __init__(self,source):
        self.source = source

    def getNextToken(self):
        #... irgendwann..
        return tokenlist.next()

    def getValue(self,key)
        # ... blublub
        return somevalue

class Symbol:
    name = None
    value = None
    type = None # int, string,..
    klass = None # const, var, functionName

    def __init__(self, name):
        self.name = name

class ParseTree:
    def __init__(self, root):
        self.root = root

class ParseTreeNode:
    children = []
    value = None # Token oder NonTerminal

    def __init__(self, value):
        self.value = value

class ThreeAddressCodeToken:


class ThreeAddressCode:
    codelist = []

    # returns code or -1 if end of list
    getNextCode():
        return someCode

###############################