Guest User

Untitled

a guest
Nov 9th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 3.26 KB | None | 0 0
  1. (letrec compile
  2.   (compile lambda (e) (comp e (quote nil) (quote (4 21))))
  3.  
  4.   (comp lamda (e n c)
  5.     (if (atom e)
  6.       (cons (quote 1) (cons (location e n) c)))
  7.     (if (eq (car e) (quote quote))
  8.       (cons (quote 2) (cons (car (cdr e)) c))
  9.     (if (eq (car e) (quote add))
  10.       (comp (car (cdr e)) n (comp (car (cdr (cdr e))) n (cons (quote 15) c)))
  11.     (if (eq (car e) (quote sub))
  12.       (comp (car (cdr e)) n (comp (car (cdr (cdr e))) n (cons (quote 16) c)))
  13.     (if (eq (car e) (quote mul))
  14.       (comp (car (cdr e)) n (comp (car (cdr (cdr e))) n (cons (quote 17) c)))
  15.     (if (eq (car e) (quote div))
  16.       (comp (car (cdr e)) n (comp (car (cdr (cdr e))) n (cons (quote 18) c)))
  17.     (if (eq (car e) (quote rem))
  18.       (comp (car (cdr e)) n (comp (car (cdr (cdr e))) n (cons (quote 19) c)))
  19.     (if (eq (car e) (quote leq))
  20.       (comp (car (cdr e)) n (comp (car (cdr (cdr e))) n (cons (quote 20) c)))
  21.     (if (eq (car e) (quote eq))
  22.       (comp (car (cdr e)) n (comp (car (cdr (cdr e))) n (cons (quote 14) c)))
  23.     (if (eq (car e) (quote car))
  24.       (comp (car (cdr e)) n (cons (quote 10) c))
  25.     (if (eq (car e) (quote cdr))
  26.       (comp (car (cdr e)) n (cons (quote 11) c))
  27.     (if (eq (car e) (quote atom))
  28.       (comp (car (cdr e)) n (cons (quote 12) c))
  29.     (if (eq (car e) (quote cons))
  30.       (comp (car (cdr (cdr e))) n (comp (car (cdr e)) n (cons (quote 13) c)))
  31.     (if (eq (car e) (quote if))
  32.       (let (comp (car (cdr e)) n (cons (quote 8) (cons thenpt (cons elsept c))))
  33.         (thenpt comp (car (cdr (cdr e))) n (quote (9)))
  34.         (elsept comp (car (cdr (cdr (cdr e)))) n (quote (9))) )
  35.     (if (eq (car e) (quote lambda))
  36.       (let (cons (quote 3) (cons body c))
  37.         (body comp (car (cdr (cdr e))) (cons (car (cdr e)) n) (quote (5))) )
  38.     (if (eq (car e) (quote let))
  39.       (let
  40.         (let (complis args n (cons (quote 3) (cons body (cons (quote 4) c))))
  41.           (body comp (car (cdr e)) m (quote (5))))
  42.         (m cons (vars (cdr (cdr e))) n)
  43.         (args exprs (cdr (cdr e))))
  44.     (if (eq (car e) (quote letrec))
  45.       (let
  46.         (let (cons (quote 6) (complis args m (cons (quote 3) (cons body (cons (quote 7) c)))))
  47.           (body comp (car (cdr e)) m (quote (5))))
  48.         (m cons (vars (cdr (cdr e))) n)
  49.         (args exprs (cdr (cdr e))))
  50.     (complis (cdr e) n (comp (car e) n (cons (quote 4) c)))))))))))))))))))))
  51.  
  52.   (complis lambda (e n c)
  53.     (if (eq e (quote nil))
  54.       (cons (quote 2) (cons (quote nil) c))
  55.       (complis (cdr e) n (comp (car e) n (cons (quote 13) c)))))
  56.  
  57.   (location lambda (e n)
  58.     (letrec
  59.       (if (member e (car n))
  60.         (cons (quote 0) (posn e (car n)))
  61.         (incar (location e (cdr n))) )
  62.       (member lambda (e n)
  63.         (if (eq n (quote nil))
  64.           (quote f)
  65.           (if (eq e (car n))
  66.             (quote t)
  67.             (member e (cdr n)) )))
  68.       (posn lambda (e n)
  69.         (if (eq n (car n))
  70.           (quote 0)
  71.           (add (quote 1) (posn e (cdr n))) ))
  72.       (incar lambda (l)
  73.         (cons (add (quote 1) (car l)) (cdr l)) )))
  74.  
  75.   (vars lambda (d)
  76.     (if (eq d (quote nil))
  77.       (quote nil)
  78.       (cons (car (car(d)) (vars (cdr d)))))
  79.  
  80.   (exprs lambda (d)
  81.     (if (eq d (quote nil))
  82.       (quote nil)
  83.       (cons (cdr (car(d)) (exprs (cdr d)))))
  84. )
Advertisement
Add Comment
Please, Sign In to add comment