This is the end of the preview. Sign up
to
access the rest of the document.

Unformatted text preview: Project 2: Scheme Interpreter CSC 4101, Fall 2011 Due: 10 November 2011 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same subset of the language as the parser for project 1, as well as some predefined functions. In particular, your interpreter should implement symbols, 32 bit integers, booleans, strings, lists, and closures; the test symbol? for identifying an identifier; the test number? for identifying integers and the binary arithmetic operations b+ , b- , b * , b/ , b= , b&lt; ; the list operations car , cdr , cons , set-car! , set-cdr! , null? , pair? , eq? ; the test procedure? for identifying a closure; the I/O functions read , write , display , newline ; the functions eval , apply , and interaction-environment . Build this interpreter on top of the code you wrote for project 1. Use the parse trees from project 1 as the internal data structure for lists. The arithmetic and list operations would then be simply implemented by the appropriate C++ (or Java) operations on parse trees. The following built-in Scheme functions call parts of your interpreter: read calls the parser and returns a parse tree, write calls the pretty-printer, eval calls your C++ or Java eval() function, apply calls your C++ or Java apply() function, interaction-environment returns a pointer to your interpreters global environment. All other built-in Scheme functions, such as and , or , not , &gt;, &gt;=, &lt;= , list , cadr , caddr , etc., equal? , map , assq , reverse , etc., can then be implemented as Scheme definitions using only the primitive operations implemented above. Since we have a general mechanism for defining functions with a variable number of arguments, the n-ary versions of the binary arithmetic operators can also be implemented in Scheme. Well do that in project 3. 1 Environments For keeping track of the values of variables during evaluation, we need a data structure for storing these values. Thats the environment. Scheme is a language with nested scopes. Given the function definition: (define (z x) (+ x y)) (define y 42) (define x 17) When evaluating the body of the function call (z y) , we need to look for the values of + , x , and y . For each variable, we first look in the local function scope, then in the outer file scope, then in the scope containing the built-in function definitions. We will find x in the function scope, y in file scope, and + in built-in scope ( + is nothing special, its a regular variable which has a function as its value). The environment data structure needs to be designed to allow this search.structure needs to be designed to allow this search....
View Full
Document