Added more examples
This commit is contained in:
parent
45e15cdb52
commit
2293603923
22
examples/collatz/collatz.q
Normal file
22
examples/collatz/collatz.q
Normal file
@ -0,0 +1,22 @@
|
||||
import log
|
||||
import sys
|
||||
|
||||
main() {
|
||||
x := 12
|
||||
|
||||
loop {
|
||||
if x & 1 == 0 {
|
||||
x /= 2
|
||||
} else {
|
||||
x = 3 * x + 1
|
||||
}
|
||||
|
||||
log.number(x)
|
||||
|
||||
if x == 1 {
|
||||
return
|
||||
}
|
||||
|
||||
sys.write(1, " ", 1)
|
||||
}
|
||||
}
|
@ -55,14 +55,16 @@ func (expr *Expression) Count(buffer []byte, kind token.Kind, name string) uint8
|
||||
|
||||
// Reset resets all values to the default.
|
||||
func (expr *Expression) Reset() {
|
||||
for _, child := range expr.Children {
|
||||
child.Reset()
|
||||
expr.Parent = nil
|
||||
|
||||
if expr.Children != nil {
|
||||
expr.Children = expr.Children[:0]
|
||||
}
|
||||
|
||||
expr.Token.Reset()
|
||||
expr.Parent = nil
|
||||
expr.Children = expr.Children[:0]
|
||||
expr.Value = 0
|
||||
expr.Precedence = 0
|
||||
expr.IsFolded = false
|
||||
}
|
||||
|
||||
// EachLeaf iterates through all leaves in the tree.
|
||||
|
@ -22,6 +22,7 @@ var examples = []struct {
|
||||
{"array", "", "Hello", 0},
|
||||
{"echo", "Echo", "Echo", 0},
|
||||
{"itoa", "", "9223372036854775807", 0},
|
||||
{"collatz", "", "6 3 10 5 16 8 4 2 1", 0},
|
||||
}
|
||||
|
||||
func TestExamples(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user