-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (37 loc) · 1.03 KB
/
main.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
from lexer import Lexer
from parser import Parser
from interpreter import Interpreter
had_error = False
repl_engaged = False
if __name__ == '__main__':
print('Welcome to susslang!')
filename = input('Press ENTER to go to REPL, or type filename <-repl> below:\n> ')
try:
chrs = ''
filenames = filename.split(' ')
for filename in filenames:
if filename == '-repl':
repl_engaged = True
continue
f = open('src/' + filename)
chrs += f.read()
chrs += '\n'
f.close()
tokens = Lexer(chrs).lex()
statements = Parser(tokens).parse()
interpreter = Interpreter()
interpreter.interpret(statements)
except:
repl_engaged = True
if repl_engaged:
interpreter = Interpreter(verbose=True)
print('REPL Initiated.')
while True:
characters = input('> ')
characters += '\n'
try:
tokens = Lexer(characters).lex()
except Lexer.LexerError:
continue
statements = Parser(tokens).parse()
interpreter.interpret(statements)