Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- code = '+[,.]'
- ip = p = 0
- stack = mem = []
- while true
- case code[ip]
- when '+'
- if mem[p] == nil
- mem[p] = 1
- else
- mem[p] += 1
- end
- when '-'
- if mem[p] == nil
- mem[p] = -1
- else
- mem[p] -= 1
- end
- when '>'
- p += 1
- when '<'
- p -= 1
- when '.'
- print mem[p].chr
- when ','
- STDOUT.flush
- input = gets.chomp[0]
- if input != nil
- mem[p] = input
- end
- when '['
- stack.push ip
- when ']'
- if mem[p] != 0
- ip = stack[-1]
- else
- stack.pop
- end
- end
- ip += 1
- if ip == code.length
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement