



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Pledge: I have neither given nor received unauthorized aid on this exam. Signature: __________________________ Name: __________________________ Begin: 3:30pm End: 5:00pm (Total: 100 points + 10 points bonus)
1. (10 points) Consider a Python dictionary that holds a mathematical term of the form
p
power (a number). The components are stored in a Python dictionary with key values 'c' , 'x' , and 'p' , respectively. Write a function named power_rule that accepts a term as the argument and returns the derivative of the term. Recall that the derivative
p
p-
p .
2. (10 points) Consider a list of integers in the form {1,02,3,0,7,21}. The list can be of arbitrary length (having anywhere from zero to infinite integers), and each integer is 1 or more digits. Write a regular expression that matches this form of list. Use the regular expression syntax we learned in class, not the Python syntax. (That is, only use
use
4. (15 points) Consider the following grammar for balanced braces:
Remove left recursion and common prefixes to create an LL(1) grammar expressing the
grammar. (Hint: think carefully before applying the algorithm to eliminate left recursion.) 5a) (6 points) Consider a procedure, (map f items) , which applies a function f to every item in a list items. For example, (map square (list 1 2 3)) returns ( 4 9) , assuming (square x) does what you expect. Write out the recursive process (not the procedure) for (map square (list 1 2 3)).
5b) (3 points) What is the base case for recursion? 5c) (6 points) Write out the procedure in Scheme. 5d) (5 points bonus) Write out the iterative process for (map square (list 1 2 3)). 5e) (5 points bonus) Write out the iterative procedure. Call it map-iter. You may assume the existence of an (append-item list item) function to append an item to the end of a list.
6d) (2 points) What is different about the namespace stack at the same point in the program in (b)? You may use words or draw another diagram to explain. (Hint: when using dynamic scope, closures do not need to maintain a link to the defining environment.) 7a) (5 points) I have a Python program called sort , and I want to run it on an x machine. Draw a Tombstone diagram to show how this is done. 7b) (5 points) I have a Python compiler that translates from Python code to x86 code. The compiler is expressed in x86 code. Show how to compile the sort program to x using Tombstone diagrams.