-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocks.lisp
48 lines (46 loc) · 1.57 KB
/
blocks.lisp
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
; This function converts an OCanada code block to a Lisp S-expression.
(defun create-block (start init)
(let ((l (list init)))
(setf i start)
(loop
(when (>= i (length code-string))(progn (format t "Sorry buddy, looks like you're missing an 'eh?' statement!")(exit)))
(cond ((equal "EH?" (elt code-string i))(return))
(t (nconc l (list (interpret-commands i))))
)
(setf i (+ i 1))
)
l
)
)
; These functions are for creating blocks for OOT and ABOOT statements.
(defun create-if-block (start init)
(let ((l (list init)))
(setf i start)
(loop
(when (>= i (length code-string))(progn (format t "Sorry buddy, looks like you're missing an 'eh?' statement!")(exit)))
(cond ((equal "EH?" (elt code-string i))(progn (setf i (- i 1))(return)))
((equal "ABOOT" (elt code-string i))(progn (setf i (- i 1))(return)))
(t (nconc l (list (interpret-commands i))))
)
(setf i (+ i 1))
)
l
)
)
(defun make-ifs (start)
(let ((l (list 'if)) (elsed 0))
(setf i start)
(nconc l (list (interpret-commands i)))
(loop
(when (>= i (length code-string))(progn (format t "Sorry buddy, looks like you're missing an 'eh?' statement!")(exit)))
(cond ((equal "EH?" (elt code-string i))(return))
((equal "ABOOT" (elt code-string i))(progn (setf elsed 1)(nconc l (list (make-ifs (+ i 1))))))
(t (nconc l (list (create-if-block i 'progn))))
)
(when (= elsed 0)
(setf i (+ i 1))
)
)
l
)
)