-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (34 loc) · 884 Bytes
/
main.py
File metadata and controls
37 lines (34 loc) · 884 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
"""
Trying to make a lisp interpreter in python
"""
import tree_parse
import lisp_interpreter
def main():
"Starts the main REPL loop"
print "Hello!"
while True:
# read
try:
i = raw_input(">>> ")
if i == "":
continue
if i == "DEBUG":
# activate debug mode
lisp_interpreter.debug = True
continue
while i.count("(") > i.count(")"):
i += raw_input("... ")
except (EOFError, KeyboardInterrupt):
break
if lisp_interpreter.debug:
print "<<< ", i
# eval
t = tree_parse.createTree(i).toList()
l = lisp_interpreter.LispStatement(t)
r = l.evaluate()
# print
print r
# loop ... (while)
print "\nBye!"
if __name__=="__main__":
main()