-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (36 loc) · 954 Bytes
/
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
46
47
48
49
50
51
from parser.Parser import Parser
from runtime.Environment import Environment
from runtime.Interpreter import evaluate
from runtime.Types import NoneVal, NumberVal, StringVal
def console()->None:
parser = Parser()
env = Environment()
print(">> W (V 0.1 ) -> ")
while True:
try:
text = input(">> ")
except EOFError:
break
if not text:
continue
elif text == "exit":
break
program = parser.parse(text)
res = evaluate(program, env)
print(res)
def from_file(file:str)->None:
with open(file, "r") as f:
text = f.read()
parser = Parser()
env = Environment()
program = parser.parse(text)
res = evaluate(program, env)
print(res)
def main() -> None:
import sys
if len(sys.argv) > 1:
from_file(sys.argv[1])
else:
console()
if __name__ == '__main__':
main()