-
Notifications
You must be signed in to change notification settings - Fork 2
/
bf2py.py
executable file
·52 lines (49 loc) · 1.14 KB
/
bf2py.py
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
#!/usr/bin/env python
import sys
indent = ' '
nest = 0
print """
import sys
data = [0]
index = 0
"""
for line in sys.stdin:
for char in line:
if char == '>':
print indent * nest + '# >'
print indent * nest + 'index += 1'
print indent * nest + 'if len(data) <= index:'
nest += 1
print indent * nest + 'data.append(0)'
nest -= 1
print
elif char == '<':
print indent * nest + '# <'
print indent * nest + 'index -= 1'
print
elif char == '+':
print indent * nest + '# +'
print indent * nest + 'data[index] += 1'
print
elif char == '-':
print indent * nest + '# -'
print indent * nest + 'data[index] -= 1'
print
elif char == '.':
print indent * nest + '# .'
print indent * nest + 'sys.stdout.write(chr(data[index]))'
print
elif char == ',':
print indent * nest + '# ,'
# ToDo
pass
print
elif char == '[':
print indent * nest + '# ['
print indent * nest + 'while data[index] != 0:'
nest += 1
print
elif char == ']':
print indent * nest + '# ]'
nest -= 1
print