-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.scm
34 lines (31 loc) · 871 Bytes
/
main.scm
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
(import (scheme base)
(scheme eval)
(scheme write)
(scheme process-context)
(tokens)
(output)
(parser))
(define (main)
(if (eqv? 2 (length (command-line)))
(repl)
(repl)))
(define (repl)
(define (loop)
(display "> ")
(let ((line (read-line)))
(if (not (or (string=? line "quit") (string=? line "exit")))
(begin
(call-with-current-continuation
(lambda (k)
(with-exception-handler
(lambda (e)
(print "Error:" e)
(k 'e))
(lambda ()
(let* ((tokens (tokenize line))
(sexp (infix->sexp tokens))
(env (environment '(scheme base))))
(print (eval sexp env)))))))
(loop)))))
(loop))
(main)