From a718ff42cea6e7490261e23e9fb37b0caa33be4e Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 8 May 2008 17:12:15 -0700 Subject: - changed literal syntax to use the convert notation - fixed issued with function declarations/function literals - added more tests and fixed existing tests SVN=118167 --- test/turing.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/turing.go (limited to 'test/turing.go') 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++; + } +} -- cgit v1.2.1