読者です 読者をやめる 読者になる 読者になる

(wat-aro)

無職から有職者にランクアップしました

SICP 問題 5.23

scheme SICP

レジスタマシン上に実装した評価器でcondとletを実装する.
cond->ifのような構文変換器が機械演算として仮定してよいので,let->lambdaも使用する.

eval-dispatch
   (test (op self-evaluating?) (reg exp))
   (branch (label ev-self-eval))
   (test (op variable?) (reg exp))
   (branch (label ev-variable))
   (test (op quoted?) (reg exp))
   (branch (label ev-quoted))
   (test (op assignment?) (reg exp))
   (branch (label ev-assignment))
   (test (op definition?) (reg exp))
   (branch (label ev-definition))
   (test (op if?) (reg exp))
   (branch (label ev-if))
   (test (op cond?) (reg exp))          ;cond?を追加
   (branch (label ev-cond))
   (test (op lambda?) (reg exp))
   (branch (label ev-lambda))
   (test (op let?) (reg exp))
   (branch (label ev-let))
   (test (op begin?) (reg exp))
   (branch (label ev-begin))
   (test (op application?) (reg exp))
   (branch (label ev-application))
   (goto (label unknown-expression-type))

 ev-cond
   (assign exp (op cond->if) (reg exp))
   (goto (label eval-dispatch))

 ev-let
   (assign exp (op let->combination) (reg exp))
   (goto (label eval-dispatch))