-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatements.go
61 lines (50 loc) · 1.1 KB
/
statements.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
package main
import "fmt"
type Statements struct {
stmts []*Statement
}
func NewStatements(stmt *Statement) *Statements {
ary := make([]*Statement, 1)
ary[0] = stmt
s := &Statements{stmts: ary}
return s
}
func (stmts *Statements) appendStatement(stmt *Statement) *Statements {
stmts.stmts = append(stmts.stmts, stmt)
return stmts
}
func (stmts *Statements) eval() Node {
var ret Node
ret = nil
for _, s := range stmts.stmts {
ret = s.eval()
if execContext.doExit {
break
}
if execContext.doReturn {
break
}
if execContext.doBreak {
break
}
if execContext.doContinue {
break
}
}
return ret
}
func (stmts *Statements) asNumber() float64 {
panic("statements can not evaluate as a number")
}
func (stmts *Statements) asString() string {
panic("statements can not evaluate as a string")
}
func (stmts *Statements) isTruthy() bool {
panic("statements can not evaluate as a truthy")
}
func (stmts *Statements) nodeType() int {
return NodeTypeStatements
}
func (stmts *Statements) String() string {
return fmt.Sprintf("[Type: Statements] (has %d statements)", len(stmts.stmts))
}