Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For each feature in this and subsequent interpreter assignments, the syntax and semantics should be the same as Scheme's unless the assignment documents specify otherwise.

For each feature in this and subsequent interpreter assignments, the syntax and semantics should be the same as Scheme's unless the assignment documents specify otherwise.
Add the Boolean constants #t, and #f to the interpreted language, along with quoted data, such as lists and vectors. Also add string literals such as "abcd". You do not need to add any string-manipulation procedures yet, but it will be nice to at least be able to use strings for output messages. Add vector literals (as with strings, Scheme will do the "real" parsing; your parse-exp simply needs to call vector? to see if an expression is a vector).
Add if expressions to the interpreted language. Most of the code is in the textbook, but you will have to adapt it to recognize and use Boolean and other literal values in addition to the numeric values. In the book's interpreted language, the authors represent true and false by numbers. In Scheme (and thus in your interpreter), any non-false value should be treated as true. The number 0 is a true value in Scheme (and in your interpreted language), but 0 is the false value in the textbook's language).
Note: Classic (i.e. not Racket) if has two forms, with and without an "else" expression. Your interpreter must eventually support both, but for this assignment only the "with" version (i.e.,two-armed if) is required for this assignment.
Add several primitive procedures including +,-,,/, add1, sub1, zero?, not, = and <(and the other numeric comparison operators), and also cons, car, cdr, list, null?, assq, eq?, equal?, atom?, length, list->vector, list?, pair?, procedure?, vector->list, vector, make-vector, vector-ref, vector?, number?, symbol?, vector-set!, display , newline to your interpreter. Add the cr and cr procedures (where each "*" stands for an "a" or "d"). Note: You may use built-in Scheme procedures in your implementation of most of the primitive procedures, as I do in the starting code that is provided for you. At least one of the above procedures has a much simpler implementation, and at least one cannot be implemented by using the corresponding Scheme procedure. You may want to enhance the prim-proc mechanism from the provided code so that a prim-proc knows how many arguments it is allowed to take, and it reports an error if the interpreted code attempts to apply it with an incorrect number of arguments. Otherwise, this incorrect code will default to a Scheme error message such as "Exception in cadr", which will make no sense to the author of the interpreted code. However, the official test cases should only test code that has no errors.
Add let (not "named-let" yet) expressions to the interpreted language, with the standard Scheme syntax: (let ([var exp]...) body1 body2...). The ... in this description is basically the same thing as the Kleene *(like the notation we used in define-syntax); it means "zero or more occurrences of the previous item". Every let expression must have at least one body. (The parser work should have been done in a previous assignment). It is okay for you to interpret named-let as well, but this is not required until a later assignment, and will be easier after we discuss letrec implementation in class. Add code that is similar to that in EoPL 3.2, allowing let expressions to be directly interpreted. Recall that after the extended environment is created, the bodies are executed in order, and the value of the last body is returned. We suggest that you test this code and understand it thoroughly before you go on to implement lambda.
Add lambda expressions of the form (lambda (var ...) body1 body2...). See the description of rep (short for "read-eval-print") below for a description of what to print if a closure or primitive procedure is part of the final value of an expression entered interactively in the interpreter. Section 3.3 of EoPL may be helpful.
In later assignments, you'll add many syntactic and semantic forms, including define, let*, letrec, cond, and set!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions