-
Notifications
You must be signed in to change notification settings - Fork 1
/
gullian.py
executable file
·45 lines (30 loc) · 1.01 KB
/
gullian.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
#!/usr/bin/python
from argparse import ArgumentParser
from gullian.source import Source
from gullian.lexer import Lexer
from gullian.parser import Parser
from gullian.checker import Checker, Module
from gullian.codegen.cgen import CGen
argparser = ArgumentParser('gullian')
argparser.add_argument('infile', type=str)
argparser.add_argument('outfile', type=str)
def compile_file(infile: str, outfile: str):
file_string = open(infile).read()
module = Module.new()
tokens = tuple(Lexer(Source(file_string), module).lex())
asts = tuple(Parser(Source(tokens), module).parse())
checker = Checker(asts, module)
for checked in checker.check():
continue
cgen = CGen(module)
out = open(outfile, 'w')
for code in cgen.gen():
out.write(code + '\n')
return
def main():
arguments = argparser.parse_args()
if arguments.infile:
return compile_file(arguments.infile, arguments.outfile)
return argparser.print_usage()
if __name__ == '__main__':
main()