-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwo.py
More file actions
executable file
·37 lines (26 loc) · 824 Bytes
/
two.py
File metadata and controls
executable file
·37 lines (26 loc) · 824 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
#!/usr/bin/env python2
import sys
from lexer.lexer import Lexer
from errors import EndOfFileError, CompilerSyntaxError, CompilerLexError
from parsers.postfix_parser import PostfixParser
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 = PostfixParser(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
if __name__ == '__main__':
main()