-
Notifications
You must be signed in to change notification settings - Fork 2
/
bf2go.go
93 lines (75 loc) · 1.39 KB
/
bf2go.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"bufio"
"os"
)
func scan() string {
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadString('\n')
return input
}
func header() {
fmt.Println(`
package main
import (
"fmt"
)
type memory [2000]int32
type Memory struct {
Pointer int
Memory memory
}
func (brain *Memory) Next() {
brain.Pointer = brain.Pointer + 1
}
func (brain *Memory) Prev() {
brain.Pointer = brain.Pointer - 1
}
func (brain *Memory) Inc() {
brain.Memory[brain.Pointer] = brain.Memory[brain.Pointer] + 1
}
func (brain *Memory) Dec() {
brain.Memory[brain.Pointer] = brain.Memory[brain.Pointer] - 1
}
func (brain *Memory) Out() {
fmt.Print(string(rune(brain.Memory[brain.Pointer])))
}
func (brain *Memory) IsNonZero() bool {
return brain.Memory[brain.Pointer] != 0
}
func main() {
var BrainMemory *Memory
BrainMemory = &Memory{
Pointer: 0}
`)
}
func printer(src string) {
switch src {
case "+":
fmt.Println("BrainMemory.Inc()")
case "-":
fmt.Println("BrainMemory.Dec()")
case ".":
fmt.Println("BrainMemory.Out()")
case ">":
fmt.Println("BrainMemory.Next()")
case "<":
fmt.Println("BrainMemory.Prev()")
case "[":
fmt.Println("for BrainMemory.IsNonZero() {")
case "]":
fmt.Println("}")
}
}
func main() {
src := scan()
header()
for _, chara := range src {
printer(string(chara))
}
fooder()
}
func fooder() {
fmt.Println("}")
}