-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathequal.go
More file actions
59 lines (45 loc) · 1.02 KB
/
equal.go
File metadata and controls
59 lines (45 loc) · 1.02 KB
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
package arithmetic
// equal (==) operator.
type equal struct{}
func (o equal) String() string {
return "=="
}
func (o equal) precedence() uint8 {
return precedenceEqual
}
func (o equal) solve(st *stack) (interface{}, error) {
// Retreive right and left terms.
right, ok := st.pop()
if !ok {
return nil, rightError(o)
}
left, ok := st.pop()
if !ok {
return nil, leftError(o, right)
}
// cast the left and right terms in the proper type (float, bool) and
// test them.
return eq(left, right), nil
}
// different (!=) operator.
type different struct{}
func (o different) String() string {
return "!="
}
func (o different) precedence() uint8 {
return precedenceEqual
}
func (o different) solve(st *stack) (interface{}, error) {
// Retreive right and left terms.
right, ok := st.pop()
if !ok {
return nil, rightError(o)
}
left, ok := st.pop()
if !ok {
return nil, leftError(o, right)
}
// cast the left and right terms in the proper type (float, bool) and
// test them.
return !eq(left, right), nil
}