diff options
author | Robert Griesemer <gri@golang.org> | 2008-05-08 17:12:15 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2008-05-08 17:12:15 -0700 |
commit | 9bc7b08abbb53469ebc39fb6617b29da0756e858 (patch) | |
tree | 6fc2b040e6b32367f31b9d6b064fad5562a300a9 /test/turing.go | |
parent | 7fbe486b1a84207b4c75664257ad538384e280d8 (diff) | |
download | go-9bc7b08abbb53469ebc39fb6617b29da0756e858.tar.gz go-9bc7b08abbb53469ebc39fb6617b29da0756e858.zip |
- changed literal syntax to use the convert notation
- fixed issued with function declarations/function literals
- added more tests and fixed existing tests
SVN=118167
Diffstat (limited to 'test/turing.go')
-rw-r--r-- | test/turing.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/turing.go b/test/turing.go new file mode 100644 index 0000000000..a7a8ea7863 --- /dev/null +++ b/test/turing.go @@ -0,0 +1,55 @@ +// $G $F.go && $L $F.$A && ./$A.out + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +// brainfuck + +func main() { + var a [30000]byte; + prog := "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."; + p := 0; + pc := 0; + for { + switch prog[pc] { + case '>': + p++; + case '<': + p--; + case '+': + a[p]++; + case '-': + a[p]--; + case '.': + print string(a[p]); + case '[': + if a[p] == 0 { + for nest := 1; nest > 0; pc++ { + if prog[pc+1] == ']' { + nest--; + } + if prog[pc+1] == '[' { + nest++; + } + } + } + case ']': + if a[p] != 0 { + for nest := -1; nest < 0; pc-- { + if prog[pc-1] == ']' { + nest--; + } + if prog[pc-1] == '[' { + nest++; + } + } + } + default: + return; + } + pc++; + } +} |