-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpr.go
128 lines (102 loc) · 2.54 KB
/
expr.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
package glox
type Expr interface {
Accept(visitor Visitor) (interface{}, error)
}
type Visitor interface {
VisitAssignExpr(expr *Assign) (interface{}, error)
VisitLogicalExpr(expr *Logical) (interface{}, error)
VisitBinaryExpr(expr *Binary) (interface{}, error)
VisitCallExpr(expr *Call) (interface{}, error)
VisitGroupingExpr(expr *Grouping) (interface{}, error)
VisitLiteralExpr(expr *Literal) (interface{}, error)
VisitUnaryExpr(expr *Unary) (interface{}, error)
VisitVarExpr(expr *VarExpr) (interface{}, error)
VisitGetExpr(expr *GetExpr) (interface{}, error)
VisitSetExpr(expr *SetExpr) (interface{}, error)
VisitThisExpr(expr *ThisExpr) (interface{}, error)
VisitSuperExpr(expr *SuperExpr) (interface{}, error)
}
type Assign struct {
Name Token
Value Expr
}
func (a *Assign) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitAssignExpr(a)
}
type Logical struct {
Left Expr
Operator Token
Right Expr
}
func (l *Logical) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitLogicalExpr(l)
}
type Binary struct {
Left Expr
Operator Token
Right Expr
}
func (b *Binary) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitBinaryExpr(b)
}
type Call struct {
Callee Expr
Paren Token
Arguments []Expr
}
func (c *Call) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitCallExpr(c)
}
type Grouping struct {
Expression Expr
}
func (g *Grouping) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitGroupingExpr(g)
}
type Literal struct {
Value interface{}
}
func (l *Literal) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitLiteralExpr(l)
}
type Unary struct {
Operator Token
Right Expr
}
func (u *Unary) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitUnaryExpr(u)
}
type VarExpr struct {
Name Token
}
func (v *VarExpr) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitVarExpr(v)
}
type GetExpr struct {
Object Expr
Name Token
}
func (g *GetExpr) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitGetExpr(g)
}
type SetExpr struct {
Object Expr
Name Token
Value Expr
}
func (se *SetExpr) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitSetExpr(se)
}
type ThisExpr struct {
Keyword Token
}
func (th *ThisExpr) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitThisExpr(th)
}
type SuperExpr struct {
Keyword Token
Method Token
}
func (se *SuperExpr) Accept(visitor Visitor) (interface{}, error) {
return visitor.VisitSuperExpr(se)
}