-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
34 lines (27 loc) · 987 Bytes
/
main.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
from src.traders_lexer import TradersLexer
from src.traders_parser import TradersParser
from src.traders_interpreter import Process
from src.traders_semantics_checker import TradersSemanticsChecker
import sys
def exec_file():
lexer = TradersLexer()
parser = TradersParser()
with open(sys.argv[1]) as opened_file:
text = opened_file.read()
tokens = lexer.tokenize(text)
tree = parser.parse(tokens)
checker = TradersSemanticsChecker(tree)
checker.check()
if checker.ok:
program = Process(tree)
try:
program.run()
except (ValueError, UnboundLocalError, NameError, IndexError, TypeError, Exception) as e:
print("Runtime error: {}".format(e))
else:
print("Semantic check failed before running.")
if __name__ == "__main__":
if len(sys.argv) != 1:
exec_file()
else:
print("Must provide a file to compile and run.")