Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / go.test / test / turing.go
blob0af39de8b203d692c27f28db99be37629903de02
1 // $G $F.go && $L $F.$A && ./$A.out
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 package main
9 // brainfuck
11 var p, pc int
12 var a [30000]byte
13 const prog = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.!"
15 func scan(dir int) {
16 for nest := dir; dir*nest > 0; pc += dir {
17 switch prog[pc+dir] {
18 case ']':
19 nest--
20 case '[':
21 nest++
26 func main() {
27 for {
28 switch prog[pc] {
29 case '>':
30 p++
31 case '<':
32 p--
33 case '+':
34 a[p]++
35 case '-':
36 a[p]--
37 case '.':
38 print(string(a[p]))
39 case '[':
40 if a[p] == 0 {
41 scan(1)
43 case ']':
44 if a[p] != 0 {
45 scan(-1)
47 default:
48 return
50 pc++