-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompiler.py
More file actions
33 lines (23 loc) · 698 Bytes
/
Compiler.py
File metadata and controls
33 lines (23 loc) · 698 Bytes
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
#
# Experimental Python3 implementation of the Compiler 435 project
import sys
import argparse
from antlr3 import *
from antlr3.tree import CommonTree
# fix Antlrs Issues
reload(sys)
sys.setdefaultencoding('utf8')
parser = argparse.ArgumentParser(description='lil compiler boi')
parser.add_argument('file', help="File to run compiler on")
def run_antlr_lexer(filename):
f = open(filename)
input_stream = ANTLRInputStream(f)
lexer = ExprLexer(input_stream)
tokens = CommonTokenStream(lexer)
parser = ExprParser(tokens)
r = parser.stat()
def main(filename):
run_antlr_lexer(filename)
if __name__ == "__main__":
args = parser.parse_args()
main(args.file)