-
Notifications
You must be signed in to change notification settings - Fork 0
/
monad-6.scm
57 lines (51 loc) · 1.45 KB
/
monad-6.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(define unit
(lambda (code)
(lambda (ctx)
(cons code ctx))))
(define >>=
(lambda (ma sequel)
(lambda (ctx)
(let ((p (ma ctx)))
(let ((code (car p))
(new/ctx (cdr p)))
((sequel code)
new/ctx))))))
(define context-search
(lambda (code)
(display "\n::")
(display code)
(newline)
(cond ((symbol? code)
(>>= (lambda (ctx)
(display "!!!!\n")
(display ctx)
(newline)
(cons
(if (assoc code ctx)
(cdr (assoc code ctx))
code)
ctx))
(lambda (code)
(unit code))))
((not (pair? code))
(unit code))
((eq? (car code) 'typedef)
(>>= (lambda (ctx)
(let ((ty (cadr code))
(alias (caddr code)))
(cons 'define-new-type-alias
(cons (cons ty alias) ctx))))
(lambda (code)
(unit code))))
(else
(>>= (context-search (car code))
(lambda (a)
(>>= (context-search (cdr code))
(lambda (d)
(unit (cons a d))))))))))
((context-search
'((typedef int integer)
(defun main (int argc, char** argv)
(int (aaa (+ 10 20))
(bbb ())))))
'())