summaryrefslogtreecommitdiff
path: root/test/turing.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2008-05-08 17:12:15 -0700
committerRobert Griesemer <gri@golang.org>2008-05-08 17:12:15 -0700
commita718ff42cea6e7490261e23e9fb37b0caa33be4e (patch)
tree6fc2b040e6b32367f31b9d6b064fad5562a300a9 /test/turing.go
parentc06e4d753e4bf662dd508ce4fe4226aaca0d7287 (diff)
downloadgo-a718ff42cea6e7490261e23e9fb37b0caa33be4e.tar.gz
- 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.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/turing.go b/test/turing.go
new file mode 100644
index 000000000..a7a8ea786
--- /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++;
+ }
+}