-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsilja.ljsp
97 lines (66 loc) · 1.63 KB
/
parsilja.ljsp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;-*- Mode: Lisp -*-
(require 'stuff)
(defvar *tokens* nil)
(defvar *sym* nil)
(defun getsym ()
(setq *tokens* (cdr *tokens*))
(setq *sym* (car *tokens*))
nil)
(defun accept (s)
(cond ((eq? *sym* s)
(getsym)
t)
(t
nil)))
(defun expect (s)
(if (accept s)
t
(error (with-output-to-string (*standard-output*)
(write-string "expect: unexpected symbol: ")
(prin1 *sym*)))))
(defun pars (tokens)
(let ((*tokens* tokens)
(*sym* (car tokens)))
(TOP)))
(defun TOP ()
(let ((a (E)))
(expect 'GIVING)
(expect 'IDENT)
(expect '())
(append a '(GIVING IDENT))))
(defun E ()
(list 'E (F) (Ep)))
(defun Ep ()
(list* 'Ep
(if (accept 'PLUS)
(list 'PLUS (E))
nil)))
(defun F ()
(list 'F (T) (Fp)))
(defun Fp ()
(list* 'Fp
(if (accept 'TIMES)
(list 'TIMES (F))
nil)))
;; (defun T ()
;; (list 'T
;; (cond ((accept 'LITERAL) 'LITERAL)
;; ((accept 'IDENT) 'IDENT)
;; (t (error "eRROLRO")))))
(defun T ()
(list 'T
(cond ((accept 'LITERAL) 'LITERAL)
((accept 'IDENT) 'IDENT)
((accept 'QUI) (let ((a (E)))
(expect 'QUE)
a))
(t (error "eRROLRO")))))
(provide 'parsilja)
;; (defun E (lst)
;; (cons (F (car lst)) (Ep (cdr lst))))
;; (defun Ep (lst)
;; (cond ((= (length lst) 0) nil)
;; ((eq? (car lst) '+) (cons '+ (E (cdr lst))))
;; (t (error "FAIL"))))
;; (defun F (lst)
;; lst)