-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfive.py
More file actions
39 lines (28 loc) · 893 Bytes
/
five.py
File metadata and controls
39 lines (28 loc) · 893 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
34
35
36
37
38
39
#!/usr/bin/env python2
import sys
from lexer.lexer import Lexer
from errors import EndOfFileError, CompilerSyntaxError, CompilerLexError, TypeNarrowError
from parsers.type_checking_parser import TCParser
def process_arguments():
if len(sys.argv) != 2:
print "Usage:\n " , sys.argv[0] , "<input_file>\n"
sys.exit(1);
filename = sys.argv[1]
return filename
def main():
filename = process_arguments()
with open(filename) as filebuffer:
try:
lex = Lexer(filebuffer)
parser = TCParser(lex)
parser.P()
except EndOfFileError:
print "Syntax error at line " + str(lex.line)
except CompilerSyntaxError as e:
print e
except CompilerLexError as e:
print e
except TypeNarrowError as e:
print e
if __name__ == '__main__':
main()