-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.go
66 lines (54 loc) · 1.27 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
package runevm
type exprType string
const (
numExpr exprType = "num"
strExpr exprType = "str"
boolExpr exprType = "bool"
varExpr exprType = "var"
assignExpr exprType = "assign"
binaryExpr exprType = "binary"
unaryExpr exprType = "unary"
funExpr exprType = "fun"
ifExpr exprType = "if"
blockExpr exprType = "block"
callExpr exprType = "call"
returnExpr exprType = "return"
whileExpr exprType = "while"
breakExpr exprType = "break"
continueExpr exprType = "continue"
arrayExpr exprType = "array"
tableExpr exprType = "table"
pairExpr exprType = "pair"
indexExpr exprType = "Index"
importExpr exprType = "import"
)
type expression struct {
Type exprType
// Multipurpose field for storing a value
Value interface{}
Left *expression
Right *expression
// Operator of binary expressions
Operator string
// If/While
Cond *expression
Then *expression
Else *expression
// Function decl
Func *expression
// Function decl param names
Params []string
// Entire block
Block []*expression
// Function call arguments
Args []*expression
// Function / while bodies
Body *expression
// Index access / Field access
Index *expression
// Token infos
File string
Line int
Col int
Length int
}