Homework Assignment # 4

Due Friday October 12, 2012 by 12:00 pm (Midnight). Use turnin to submit your homework (i.e., turnin -submit [MW use swati, TTh use benself] CS345_HW4 HW4.scm , HW4.rkt, and Parser.jj)

Please include your EID in every file of your homework. If you do not include your EID in every file, you will receive a 0. It will be as if you did not submit it. If the file is code, include your EID as a comment at the top of the file. If it's not code, put your EID at the top of the file.

1. [3 Points] Write the differentiation function found in the PLAI book in Section 6.5.2 in scheme using lets and lambdas instead of defines. It should have 3 lets, one for H, one for the function being differentiated and one for d/dx.

Rewrite this expression as just function applications as shown in PLAI 3 & HLL 3, page 3.

Put both of these expressions in the HW4.csm file.

2. [3 Points] Update the FAE language found in "Scheme for Chapters 4, 5, and 6 Final" to have -, *, and / functions. Write the differentiation expression found in the PLAI book in Section 6.5.2 in FAE using withs and funs instead of defines. Write an Environment (repository of deferred substitutions) for this differentiation that can be used with (interp (parse '{d/dx 10}).

Put differentiation expression and the (interp (parse '{d/dx 10}) Environment) expression at the end of the FAE definitions in the file HW4.rkt.

3. [4 Points] Write a parser in javacc that converts scheme let expressions to lambda applications as shown in PLAI 3 & HLL 3, page 3.

Hint: You might want to take the crono grammar, remove the crono ast items, the actions and return values from non-terminals and then add your own return values and actions. You may want to use the following code from homework 3 instead of what's in the crono .jj file, but change parser.ae() to something appropriate.


import java.io.*;
import java.util.*;

public class Parser {
public static void main(String args[]) throws ParseException {
Parser parser = new Parser (System.in);


The output from the following expression:

echo "(let ((H .001)) (let ((f (lambda (x) (* x x x x)))) (let ((d/dx (lambda (x) (/ (- (f (+ x H))(f x)) H)))) (d/dx 10))))" | java Parser

should look something like the following:

( (lambda (H) ( (lambda (f) ( (lambda (d/dx) ( d/dx 10))( lambda( x)( /( -( f( + x H))( f x)) H))))( lambda( x)( * x x x x)))) .001)