-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.py
More file actions
68 lines (61 loc) · 3.61 KB
/
repl.py
File metadata and controls
68 lines (61 loc) · 3.61 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from lisp_exceptions import *
from interpreter import Interpreter
'''
REPL interface for interacting with the interpreter
'''
class REPL:
"""Lisp read-eval-print loop class"""
def __init__(self):
interpreter = Interpreter()
print("""
///////////////////////////////////////////////////////////////////////////////
// //
// Lisp REPL and Interpreter //
// Author: Ryan Cebulko //
// Created: 1/2015 //
// //
// This was a little project written one night when a friend posed me the //
// challenge of writing a Lisp interpreter in Python. Having no experience //
// using Python for anything but Hello World, I thought it would be a fun //
// project. It was. //
// //
// Data types: //
// -integer //
// -float //
// -symbol //
// -list/cons //
// -boolean //
// -lambda function //
// Current Features: //
// -local bindings with 'let' //
// -boolean operators //
// -arithmetic operators //
// -function currying //
// -if branches //
// -cond blocks //
// Missing Features: //
// -global definitions //
// -recursive bindings without using a Y-combinator //
// -lazy evaluation //
// -arbitrary number of arguments for functions like + and or //
// -tests for the parser (I was tired and lazy writing that bit) //
// -parser error handling (same reason as above) //
// -(help) and (exit) functions //
// //
///////////////////////////////////////////////////////////////////////////////
""")
while True:
try:
print(interpreter.run(raw_input("\n>>> ")))
except LispParsingException, e:
print("LispParsingException in " + str(e))
except LispCompilationException, e:
print("LispCompilationException in " + str(e))
except LispRuntimeException, e:
print("LispRuntimeException in " + str(e))
except LispRuntimeException, e:
print("LispRuntimeException in " + str(e))
except Exception, e:
print(e)
if __name__ == '__main__':
REPL()