Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func runCode(program string) {
- data := make([]byte, 100000)
- ip := 0
- dp := 0
- ld := 0
- for ; ip < len(program); ip++ {
- switch program[ip] {
- case '+':
- data[dp]++
- case '-':
- data[dp]--
- case '>':
- dp++
- case '<':
- dp--
- case '.':
- fmt.Print(string(data[dp]))
- case ',':
- b := make([]byte, 1)
- os.Stdin.Read(b)
- data[dp] = b[0]
- case '[':
- if data[dp] == 0 {
- ip++
- for ld > 0 || program[ip] != ']' {
- if program[ip] == '[' {
- ld++
- } else if program[ip] == ']' {
- ld--
- }
- ip++
- }
- }
- case ']':
- if data[dp] != 0 {
- ip--
- for ld > 0 || program[ip] != '[' {
- if program[ip] == ']' {
- ld++
- } else if program[ip] == '[' {
- ld--
- }
- ip--
- }
- ip--
- }
- }
- }
- fmt.Println()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement