-
Notifications
You must be signed in to change notification settings - Fork 0
/
geubsikpy.py
58 lines (40 loc) · 1.54 KB
/
geubsikpy.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
56
57
58
import argparse
import pathlib
import sys
import time
from compiler.lexer import CanonicalLexer
from core.dynamic.Exec import Interpret
from core.static.Loader import LoadFromFile
from generators.GenerateFile import FileGenerator
from generators.GenerateProgram import ProgramStringBuilder
def main(command: str, s: str) -> int:
if not s.endswith(".기모띠"):
print("확장자는 기모띠여야지 바보야")
return 0
start_time = time.time()
program_loader = LoadFromFile(s)
generator = CanonicalLexer.PythonGenerator()
program_string = ProgramStringBuilder()
for token in generator.gen(program_loader):
# print(token)
program_string.build(token)
complete_time = time.time() - start_time
if command == "run":
Interpret(s).exec(program_string.to_string())
elif command == "build":
FileGenerator.gen(
pathlib.Path(s).name.replace(".기모띠", "") + ".py", program_string.to_string()
)
print("\n%.5f초만에 끝났다." % complete_time)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="command")
parser_run = subparsers.add_parser("run")
parser_run.add_argument("FILE", metavar="FILE", type=str)
parser_build = subparsers.add_parser("build")
parser_build.add_argument("FILE", metavar="FILE", type=str)
args = parser.parse_args()
if not hasattr(args, "FILE"):
parser.print_help()
sys.exit(0)
sys.exit(main(command=args.command, s=args.FILE))