Skip to content

Commit 46858aa

Browse files
committed
[ENH] make main a bit more professionnal
1 parent 25b7bc7 commit 46858aa

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

main.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#! /usr/bin/python3.5
22

3+
import sys
4+
35
from parser.parser import *
46
from execution.execution import *
57

8+
ex = sys.modules['execution.execution']
9+
10+
example_filename = 'examples/WIL/push_dup.ws'
11+
612
def get_loop_instructions():
7-
return loop_instructions = [
13+
return [
814
('push', 1),
915
('label', 0),
1016
'dup',
@@ -18,14 +24,20 @@ def get_loop_instructions():
1824
'end'
1925
]
2026

21-
def main():
22-
pass
23-
24-
if __name__ == '__main__':
25-
filename = 'examples/WIL/push_dup.ws'
27+
def main(filename):
2628
p = Parser()
2729
c = open(filename, 'r').read()
2830
content = p.remove_forbidden_chars(c)
2931
instructions = p.parse(content)
3032
print(instructions)
3133
execute(instructions)
34+
35+
def usage():
36+
print('usage: ./main.py file_to_execute.ws')
37+
38+
if __name__ == '__main__':
39+
ex.DEBUG = False
40+
if len(sys.argv) != 2:
41+
usage()
42+
sys.exit(1)
43+
main(sys.argv[1])

0 commit comments

Comments
 (0)