/
ast.go
75 lines (60 loc) · 1.33 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
package gocalc
// All expressions implement the expr interface.
type expr interface {
accept(exprVisitor)
}
type (
// A binaryExpr represents a binary expression.
binaryExpr struct {
left expr // left operand
op *token // binary operator
right expr // right operand
}
// A funcExpr represents a function call.
funcExpr struct {
function string // function name
args []expr // argument list
}
// A paramExpr represents a parameter.
paramExpr struct {
identifier string // parameter name
}
// A unaryExpr represents a unary expression.
unaryExpr struct {
expr expr // operand
op *token // unary operator
}
// A boolExpr represents a boolean literal.
boolExpr struct {
val bool
}
// A floatExpr represents a float literal.
floatExpr struct {
val float64
}
// An intExpr represents a integer literal.
intExpr struct {
val int64
}
)
func (b *binaryExpr) accept(v exprVisitor) {
v.visitBinaryExpr(b)
}
func (f *funcExpr) accept(v exprVisitor) {
v.visitFuncExpr(f)
}
func (p *paramExpr) accept(v exprVisitor) {
v.visitParamExpr(p)
}
func (u *unaryExpr) accept(v exprVisitor) {
v.visitUnaryExpr(u)
}
func (b *boolExpr) accept(v exprVisitor) {
v.visitBoolExpr(b)
}
func (f *floatExpr) accept(v exprVisitor) {
v.visitFloatExpr(f)
}
func (i *intExpr) accept(v exprVisitor) {
v.visitIntExpr(i)
}