{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture17 - M ETA C IRCULAR E VALUATOR G EORGE WANG...

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

View Full Document Right Arrow Icon
M ETA C IRCULAR E VALUATOR 17 G EORGE W ANG [email protected] Department of Electrical Engineering and Computer Sciences University of California, Berkeley July 20, 2010 Introduction One thing that comes up is that you might think that it’s best to write an evaluator that is designed to read in a easy language, but also to use a really powerful language that is capable of dealing with complex structures and dealing with symbols. However, it turns out that these two languages can be the same language. Furthermore, we can use Scheme for both of these, since its structure of syntax is simple to parse, and it is great at handling symbols. One important question to address is why it’s useful to write a Scheme compiler in Scheme, since obviously you’d have to have something that reads that in the first place. First of all, there’s a good pedagogical reason for doing it. By doing so, you will have a much stronger image of how something like that works, as well as have a good idea of how Scheme itself works. We’ll be implementing the page of code that is essentially our rules for evaluating environment diagrams. Secondly, it turns out much of Scheme itself is implemented in Scheme. Once you get out of memory management and such, it turns out a lot of STk is actually written in Scheme as well. Thirdly, we will be able to add new features and change fundamentally the way Scheme works for us. Lastly, there’s a very very powerful idea, which is called UNIVERSALITY . Universality means we can write one program that’s equivalent to all other programs that can ever be written. At the hardware level, this is the idea that made general-purpose computers possible. It used to be that they built a separate machine, from scratch, for every new problem. An intermediate stage was a machine that had a patchboard so you could rewire it, effectively changing it into a different machine for each problem, without having to re- manufacture it. The final step was a single machine that accepted a program as data so that it can do any problem without rewiring. This is the ultimate in data-directed programming. 1
Background image of page 1

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

View Full Document Right Arrow Icon
1 First Version: Echo Let’s write this first version, that doesn’t do anything interesting, except read your input and spit it back out at you. You also can’t actually quit out of it... ;cs61a/lectures/mceval/mc-eval-step1.scm (define (input-loop) (display "=61A=> ") (print (mc-eval (read))) (input-loop) (define (mc-eval exp) exp) So this is pretty dumb, but it introduces two things. It has a way of reading input from the user, as well as a procedure that is supposed to evaluate what an expression evaluates into.
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.

{[ snackBarMessage ]}