程序代写代做代考 DrRacket Java html interpreter 10/18/2020

10/18/2020
Programming Languages Home􏰌ork 6
CSCI 4430 Programming Languages
Home􏰌ork 5: Scheme Part 1
D􏰎􏰏: F􏰐􏰑􏰒a􏰓 O􏰔􏰕􏰖b􏰏􏰐 23 @ 1:59􏰗􏰘 S􏰎b􏰘􏰑􏰙􏰙􏰑􏰖􏰚 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􏰕 A􏰚􏰖􏰕he􏰐 B􏰖􏰖􏰜ea􏰚 I􏰚􏰕e􏰐􏰗􏰐e􏰕e􏰐
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 e􏰞pr ) e􏰞pr 􏰝 id
e􏰞pr 􏰝 const
e􏰞pr 􏰝 ( m􏰓ignore e􏰞pr ) e􏰞pr 􏰝 ( m􏰓or e􏰞pr e􏰞pr ) e􏰞pr 􏰝 ( m􏰓and e􏰞pr e􏰞pr ) e􏰞pr 􏰝 ( m􏰓no􏰕 e􏰞pr )
e􏰞pr 􏰝 ( m􏰓le􏰕 id e􏰞pr e􏰞pr ) id 􏰝a􏰟b􏰟 … 􏰟􏰠
const 􏰝 􏰕r􏰎e 􏰟 fal􏰙e
Here are five valid BOOL programs
(prog 􏰕r􏰎e)
(prog (m􏰓or (m􏰓and 􏰕r􏰎e (m􏰓ignore (m􏰓or 􏰕r􏰎e fal􏰙e))) (m􏰓and 􏰕r􏰎e fal􏰙e)))
(prog (m􏰓le􏰕 􏰠 (m􏰓or fal􏰙e 􏰕r􏰎e) (m􏰓and 􏰠 􏰕r􏰎e)))
(prog (m􏰓le􏰕 a 􏰕r􏰎e (m􏰓or (m􏰓le􏰕 b (m􏰓and 􏰕r􏰎e fal􏰙e) (m􏰓or fal􏰙e b)) (m􏰓and
fal􏰙e a))))
(prog (m􏰓le􏰕 􏰞 􏰕r􏰎e (m􏰓or (m􏰓le􏰕 􏰞 (m􏰓and 􏰕r􏰎e fal􏰙e) (m􏰓and 􏰕r􏰎e 􏰞)) (m􏰓and
􏰕r􏰎e 􏰞))))
Each BOOL program and expression evaluates to a boolean value. The semantics of a program is defined as follows:
The entire program ( prog e􏰞pr ) evaluates to whatever e􏰞pr evaluates to.
( m􏰓ignore e􏰞pr ) evalutes to the boolean value #f, regardless of what the subexpression e􏰞pr looks like.
( m􏰓and e􏰞pr e􏰞pr ) evaluates to the logical conjunction of whatever values the two subexpressions evaluate to.
edda G
https://􏰌􏰌􏰌.cs.rpi.edu/􏰍milanova/csci4430/h􏰌4.html 1/2

G-
The
10/18/2020
Programming Languages Home􏰌ork 6
( m􏰓or e􏰞pr e􏰞pr ) evaluates to the logical disjunction of whatever values the two subexpressions evaluate to.
( m􏰓no􏰕 e􏰞pr ) evaluates to the negation of X, where X is the boolean value that the subexpression evaluates to.
( m􏰓le􏰕 id e􏰞pr1 e􏰞pr2 ) has the following semantics. First, subexpression e􏰞pr1 is evaluated. The resulting boolean value is “bound” to the identifier id. Then the second subexpression, e􏰞pr2 is evaluated. The result of that evaluation serves as the value of the entire m􏰓le􏰕 expression. The binding between the id and the boolean value is active 􏰖􏰚􏰜􏰓 while e􏰞pr2 is being evaluated!
id evaluates to the value that the identifier is bound to by a surrounding m􏰓le􏰕 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 fa􏰜􏰙e 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 􏰘􏰓i􏰚􏰕e􏰐􏰗􏰐e􏰕e􏰐 that takes as input a 􏰜􏰑􏰙􏰕 􏰖f BOOL 􏰗􏰐􏰖g􏰐a􏰘􏰙 and produces a 􏰜􏰑􏰙􏰕 􏰖f 􏰕􏰡e c􏰖􏰐􏰐e􏰙􏰗􏰖􏰚d􏰑􏰚g b􏰖􏰖􏰜ea􏰚 􏰢a􏰜􏰎e􏰙. For example, an invocation
( 􏰘􏰓i􏰚􏰕e􏰐􏰗􏰐e􏰕e􏰐 ‘( (􏰗􏰐􏰖g fa􏰜􏰙e) (􏰗􏰐􏰖g (􏰘􏰓􏰜e􏰕 􏰠 (􏰘􏰓􏰖􏰐 􏰕􏰐􏰎e fa􏰜􏰙e) (􏰘􏰓a􏰚d 􏰠 􏰕􏰐􏰎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 b􏰖􏰖􏰖􏰜ea􏰚?. 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 e􏰣􏰎a􏰜?, ca􏰐, cd􏰐, c􏰖􏰚􏰙, c􏰖􏰚d, if, 􏰖􏰐, a􏰚d, 􏰚􏰖􏰕, 􏰚􏰎􏰜􏰜?, 􏰙􏰓􏰘b􏰖􏰜?, and b􏰖􏰖􏰜ea􏰚?. You should 􏰚􏰖􏰕 􏰎􏰙e a􏰚􏰓 􏰖􏰕􏰡e􏰐 b􏰎􏰑􏰜􏰕-􏰑􏰚 f􏰎􏰚c􏰕􏰑􏰖􏰚.
You must comment your code! You are requried to write comments in the style described here. Minimal starter code is provided here.
NOTE 􏰖􏰚 g􏰐ad􏰑􏰚g: 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.
E􏰐􏰐a􏰕a
None yet. Check the Announcements page regularly.
ahttps://􏰌􏰌􏰌.cs.rpd s

i.edu/􏰍milanova/csc
i4430/h􏰌4.html 2/2