-
Notifications
You must be signed in to change notification settings - Fork 1
/
wise.py
55 lines (54 loc) · 1.18 KB
/
wise.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
50
51
52
53
54
55
import optparse
from Interpreter import Interpreter
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option(
"-b",
"--binary",
dest="OUTPUT",
action="store_const",
const="b",
default="i",
help="Formats output as binary"
)
parser.add_option(
"-a",
"--ascii",
dest="OUTPUT",
action="store_const",
const="a",
help="Formats output as ASCII",
)
parser.add_option(
"-f",
"--file",
dest="filename",
help="File name for input arguments"
)
(options, args) = parser.parse_args()
try:
f = open(args[0])
except:
print "Please provide a valid file."
else:
if options.filename:
try:
g = open(options.filename)
except:
print "There was an error opening %s"%(options.filename)
else:
try:
input = map(int,g.read().split())
except:
#TODO make more descriptive error
print "Error reading file %s"%(options.filename)
interpreter = Interpreter(f.read(),options.OUTPUT,*input)
g.close()
f.close()
while interpreter.step():pass
print interpreter
else:
interpreter = Interpreter(f.read(),options.OUTPUT,*map(int,args[1:]))
f.close()
while interpreter.step():pass
print interpreter