Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import readchar
- def block(code):
- opened = []
- blocks = {}
- for i in range(len(code)):
- c = ord(code[i])
- c = c>>2&4|c&3
- if c == 7:
- opened.append(i)
- elif c == 5:
- blocks[i] = opened[-1]
- blocks[opened.pop()] = i
- return blocks
- def parse(code):
- return ''.join(c for c in code if c > ' ')
- def run(code):
- code = parse(code)
- x = [0]
- i = [0]
- bf = {0: 0}
- blocks = block(code)
- l = len(code)
- procs = (
- (lambda: bf.__setitem__(x, ord(readchar()))),
- (lambda: (bf[x[0]] == 0 and [bf.__setitem__(x[0], 255)] or [bf.__setitem__(x[0], bf[x[0]] - 1)])[0]),
- (lambda: print(chr(bf[x[0]]), end='')),
- (lambda: (bf[x[0]] == 255 and [bf.__setitem__(x[0], 0)] or [bf.__setitem__(x[0], bf[x[0]] + 1)])[0]),
- (lambda: x.__setitem__(0, x[0] - 1)),
- (lambda: bf[x[0]] and i.__setitem__(0, blocks[i[0]])),
- (lambda: (x.__setitem__(0, x[0] + 1), bf.setdefault(x[0], 0))),
- (lambda: not bf[x[0]] and i.__setitem__(0, blocks[i[0]])))
- while i[0] < l:
- sym = ord(code[i[0]])
- sym = sym>>2&4|sym&3
- procs[sym]()
- i[0] += 1
- f = open(sys.argv[1], 'r')
- code = f.read()
- f.close()
- run(code)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement