(flush(let(input(read(if(equal input'exit(print"Au"/>

analyze-final - Analyzing...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;; Analyzing Evaluator (define (input-loop) (display "=61A(Analyzer)=> ") (flush) (let ((input (read))) (if (equal? input 'exit) (print "Au Revoir!") (begin (print (mc-eval (analyze input) the-global-env)) (input-loop))))) (define (analyze exp) (cond ((self-evaluating? exp) (lambda (env) exp)) ((variable? exp) (lambda (env) (lookup-variable-value exp env))) ((quote-exp? exp) (lambda (env) (cadr exp))) ((if-exp? exp) (lambda (env) (let ((analyzed-tf (analyze (cadr exp))) (analyzed-true (analyze (caddr exp))) (analyzed-false (analyze (cadddr exp)))) (if (not (eq? (mc-eval analyzed-tf env) 'nay)) (mc-eval analyzed-true env) (mc-eval analyzed-false env))))) ((definition? exp) (if (list? (cadr exp)) (analyze (define->lambda exp)) (lambda (env) (let ((analyzed-value (analyze (caddr exp)))) (define-variable! (cadr exp) (mc-eval analyzed-value env) env))))) ((set-exp? exp) (let ((analyzed-value (analyze (caddr exp)))) (lambda (env) (set-variable-value! (cadr exp) (mc-eval analyzed-value env) env)))) ((begin-exp? exp) (lambda (env) (let ((analyzed-exps (map analyze (cdr exp)))) (eval-sequence analyzed-exps env)))) ((lambda-exp? exp) (lambda (env) (let ((analyzed-body (map analyze (cddr exp))))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at Berkeley.

Page1 / 5

analyze-final - Analyzing...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online