-
Notifications
You must be signed in to change notification settings - Fork 0
/
bf.py
44 lines (37 loc) · 875 Bytes
/
bf.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
from bfparser import Parser
from bfcompiler import Compiler
from bfdecompiler import Decompiler
from bfinterpreter import Interpreter
import sys
import os
def run(code, debug=False):
p = Parser(code)
p.parse()
c = Compiler(p.ast)
b = c.compile()
if debug:
print p.ast
print b
d = Decompiler(b)
d.decompile()
i = Interpreter(b)
i.run()
print
def main():
if len(sys.argv) == 1:
print "Missing input"
else:
inp = sys.argv[1]
if os.path.exists(inp):
f = open(inp, 'r')
code = f.read()
f.close()
else:
code = inp
if len(sys.argv) >= 3 and sys.argv[2] == "-debug":
debug = True
else:
debug = False
run(code, debug)
if __name__ == '__main__':
main()