-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.go
143 lines (122 loc) · 3.08 KB
/
ast.go
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
package main
type TermKind string
const (
KindInt TermKind = "Int"
KindStr TermKind = "Str"
KindBool TermKind = "Bool"
KindBinary TermKind = "Binary"
KindCall TermKind = "Call"
KindFunction TermKind = "Function"
KindLet TermKind = "Let"
KindIf TermKind = "If"
KindPrint TermKind = "Print"
KindFirst TermKind = "First"
KindSecond TermKind = "Second"
KindTuple TermKind = "Tuple"
KindVar TermKind = "Var"
)
type BinaryOp string
const (
Add BinaryOp = "Add"
Sub BinaryOp = "Sub"
Mul BinaryOp = "Mul"
Div BinaryOp = "Div"
Rem BinaryOp = "Rem"
Eq BinaryOp = "Eq"
Neq BinaryOp = "Neq"
Lt BinaryOp = "Lt"
Gt BinaryOp = "Gt"
Lte BinaryOp = "Lte"
Gte BinaryOp = "Gte"
And BinaryOp = "And"
Or BinaryOp = "Or"
)
type Term interface{}
type Int struct {
Kind TermKind `json:"kind"`
Value int32 `json:"value"`
Location Location `json:"location"`
}
type Str struct {
Kind TermKind `json:"kind"`
Value string `json:"value"`
Location Location `json:"location"`
}
type Bool struct {
Kind TermKind `json:"kind"`
Value bool `json:"value"`
Location Location `json:"location"`
}
type Binary struct {
Kind TermKind `json:"kind"`
LHS Term `json:"lhs"`
Op BinaryOp `json:"op"`
RHS Term `json:"rhs"`
Location Location `json:"location"`
}
type Print struct {
Kind TermKind `json:"kind"`
Value Term `json:"value"`
Location Location `json:"location"`
}
type First struct {
Kind TermKind `json:"kind"`
Value Term `json:"value"`
Location Location `json:"location"`
}
type Second struct {
Kind TermKind `json:"kind"`
Value Term `json:"value"`
Location Location `json:"location"`
}
type If struct {
Kind TermKind `json:"kind"`
Condition Term `json:"condition"`
Then Term `json:"then"`
Otherwise Term `json:"otherwise"`
Location Location `json:"location"`
}
type Tuple struct {
Kind TermKind `json:"kind"`
First Term `json:"first"`
Second Term `json:"second"`
Location Location `json:"location"`
}
type Parameter struct {
Text string `json:"text"`
Location Location `json:"location"`
}
type Call struct {
Kind TermKind `json:"kind"`
Callee Term `json:"callee"`
Arguments []Term `json:"arguments"`
Location Location `json:"location"`
}
type Let struct {
Kind TermKind `json:"kind"`
Name Parameter `json:"name"`
Value Term `json:"value"`
Next Term `json:"next"`
Location Location `json:"location"`
}
type Var struct {
Kind TermKind `json:"kind"`
Text string `json:"text"`
Location Location `json:"location"`
}
type Function struct {
Kind TermKind `json:"kind"`
Parameters []Parameter `json:"parameters"`
Value Term `json:"value"`
Location Location `json:"location"`
}
type File struct {
Name string `json:"name"`
Expression Term `json:"expression"`
Location Location `json:"location"`
}
type Location struct {
Start uint32 `json:"start"`
End uint32 `json:"end"`
Filename string `json:"filename"`
}