10/18/2020
Programming Languages Homeork 6
CSCI 4430 Programming Languages
Homeork 5: Scheme Part 1
D: Fa Ob 23 @ 1:59 Sb I
This is an individual assignment! Discussion with friends, TAs, and instructors is allowed, however, the actual work should be your own. Course staff runs plagiarism detectors, and will treat excessive similarities between submissions as evidence of cheating. Submit in Submitty. Your Scheme file should be named abi.. Submitty runs a command-line r5rs interpreter. Make sure that you change the language in DrRacket to R5RS!
Ye Ahe Bea Ieee
We’ve written Boolean expression interpreters in Java and Prolog, and it’s time to write one in Scheme! The goal of this problem is to write an interpreter for a simple functional language called BOOL. A BOOL program is a list, as defined by the following grammar; all terminals are shown in boldface.
program ( prog epr ) epr id
epr const
epr ( mignore epr ) epr ( mor epr epr ) epr ( mand epr epr ) epr ( mno epr )
epr ( mle id epr epr ) id ab …
const re fale
Here are five valid BOOL programs
(prog re)
(prog (mor (mand re (mignore (mor re fale))) (mand re fale)))
(prog (mle (mor fale re) (mand re)))
(prog (mle a re (mor (mle b (mand re fale) (mor fale b)) (mand
fale a))))
(prog (mle re (mor (mle (mand re fale) (mand re )) (mand
re ))))
Each BOOL program and expression evaluates to a boolean value. The semantics of a program is defined as follows:
The entire program ( prog epr ) evaluates to whatever epr evaluates to.
( mignore epr ) evalutes to the boolean value #f, regardless of what the subexpression epr looks like.
( mand epr epr ) evaluates to the logical conjunction of whatever values the two subexpressions evaluate to.
edda G
https://.cs.rpi.edu/milanova/csci4430/h4.html 1/2
G-
The
10/18/2020
Programming Languages Homeork 6
( mor epr epr ) evaluates to the logical disjunction of whatever values the two subexpressions evaluate to.
( mno epr ) evaluates to the negation of X, where X is the boolean value that the subexpression evaluates to.
( mle id epr1 epr2 ) has the following semantics. First, subexpression epr1 is evaluated. The resulting boolean value is “bound” to the identifier id. Then the second subexpression, epr2 is evaluated. The result of that evaluation serves as the value of the entire mle expression. The binding between the id and the boolean value is active while epr2 is being evaluated!
id evaluates to the value that the identifier is bound to by a surrounding mle expression. If there are multiple bindings for the identifier, the last (i.e., latest) such binding is used.
const e evaluates to Scheme’s # and const fae evaluates to #f.
Based on these rules, the five programs from above are evaluated as follows:
Program 1 evaluates to # Program 2 evaluates to #f Program 3 evaluates to # Program 4 evaluates to #f Program 5 evaluates to #
Write a Scheme function ieee that takes as input a f BOOL ga and produces a f e cedg bea ae. For example, an invocation
( ieee ‘( (g fae) (g (e ( e fae) (ad e))) ) ) should evaluate to the list (#f #). Your implementation should work with the R5RS Language in
DrRacket.
You are guaranteed that the list given to the interpreter will not be empty, and will contain only valid BOOL programs. Also, you may assume that any evaluation of an identifier has at least one existing binding for that identifier.
Useful library functions for your implementation are b? and bea?. The first checks if the argument is a symbol such as a, e, etc. The second checks if the argument is a boolean value.
In order to maintain the set of bindings, consider using a list where each element of the list is one specific binding. A binding is really just a pair of an identifier and a boolean value.
The only built-in Scheme functions you are allowed to use are ea?, ca, cd, c, cd, if, , ad, , ?, b?, and bea?. You should e a e b- fc.
You must comment your code! You are requried to write comments in the style described here. Minimal starter code is provided here.
NOTE gadg: This homework is worth a total of 40 points. (Scheme Part 2 is worth 60 points.) 30 points will be awarded for functional correctness by the autograder. However, we will override the autograder if you have violated the restrictions on functions! 10 points will be awarded for the quality and completeness of your comments.
Eaa
None yet. Check the Announcements page regularly.
ahttps://.cs.rpd s
–
i.edu/milanova/csc
i4430/h4.html 2/2