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

analyze-step1 - Analyzing...

Info iconThis preview shows pages 1–3. 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) exp) ((variable? exp) exp) ((if-exp? exp) (list 'if (analyze (cadr exp)) (analyze (caddr exp)) (analyze (cadddr exp)))) ((definition? exp) (if (list? (cadr exp)) (analyze (define->lambda exp)) (list 'define (cadr exp) (analyze (caddr exp))))) ((begin-exp? exp) (cons 'begin (map analyze (cdr exp)))) ((lambda-exp? exp) (append (list 'lambda (cadr exp)) (map analyze (cddr exp)))) ((list? exp) (transform-proc-call exp)) (else (error "UNKNOWN expression")))) (define (transform-proc-call exp) (let ((analyzed-fn (analyze (car exp))) (analyzed-args (map analyze (cdr exp)))) (lambda (env) (mc-apply (mc-eval analyzed-fn env) (map (lambda (arg) (mc-eval arg env)) analyzed-args))))) (define (transformed? exp) (procedure? exp)) (define (mc-eval exp env) (display "MC-Eval: ") (display exp) (newline) (cond ((transformed? exp) (exp env)) ((self-evaluating? exp) exp) ((variable? exp) (lookup-variable-value exp env)) ((if-exp? exp) (if (not (eq? (mc-eval (cadr exp) env) 'nay)) (mc-eval (caddr exp) env) (mc-eval (cadddr exp) env)))
Background image of page 1

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

View Full DocumentRight Arrow Icon
((begin-exp? exp)
Background image of page 2
Image of page 3
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-step1 - Analyzing...

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

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