forked from VPanjeta/ModiScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMODI
More file actions
executable file
·52 lines (40 loc) · 1.15 KB
/
MODI
File metadata and controls
executable file
·52 lines (40 loc) · 1.15 KB
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
#!/usr/bin/env python3
import os
import sys
from lexer import Lexer
from parser import Parser
from utils import ErrorHandler, FNF, usage
DEBUG = False
def compile_file(filename):
global DEBUG
lex_out = Lexer(filename).analyze()
if DEBUG:
with open(filename.split('.', 1)[0] + ".txt", "w") as f:
print(*lex_out, sep='\n', file=f)
parse_out = Parser(lex_out).parse()
if DEBUG:
with open(filename.split('.', 1)[0] + ".py", "w") as f:
import ast
print(ast.dump(parse_out), file=f)
return compile(parse_out, "<ast>", "exec")
def execute(filename):
ast_module = compile_file(filename)
exec(ast_module)
def main():
if len(sys.argv) < 2 or '-h' in sys.argv or '--help' in sys.argv:
usage()
filename = sys.argv[-1]
#filename = "modi.chai"
if '-d' in sys.argv or '--debug' in sys.argv:
global DEBUG
DEBUG = True
# check existence
if not os.path.isfile(filename):
raise ErrorHandler(FNF, filename)
# execute
execute(filename)
if __name__ == '__main__':
try:
main()
except ErrorHandler as e:
print(e)