Homework3 - Now please implemen t an RPAL function...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 5555 Programming Language Principles Homework 3 Assigned: June 1, 2011 Deadline: 11:59pm Jun. 8, 2011 *Note: Please submit your solution to the e-learning system by the deadline. No late submission is allowed. 1. Problem 1 (30 Points) Using the RPAL string-to-tree-transduction grammar, draw the abstract syntax tree (if possible) for each of the following programs: (a) x or y -> x | z -> x | y (b) x eq y -> z -> x| y| x (c) x aug y, z, 3 (d) x, y, z aug 3 (e) ( (let f(x) = x*2+1) in (f(z) where z=6) ) (f) item (e) above with all the parentheses removed (g) let x = z and y = 2 * z where z = 3 in x** y**y (h) let x = y in x * z ** y where z = 4 and p = 3* y 2. Problem 2 (20 Points) In problem 1, the structure of each program is not apparen t because the program is written on a single line as a linear string. Re-write each program on several lines, indenting appropriately to reflect the structure. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
3. Problem 3 (25 Points) The integer operator “**" in RPAL raises an integer to an integer power.
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Now please implemen t an RPAL function called "power” to achieve the same functionality. For example (power 3 2) returns the same v alue as (2**3), which is 8. Your function should use the fact that x2n = ( x 2 ) n to reduce the number of multiplications required. You are not allowed to use "**" operator in the function. (Note: Please submit a separate “ p3.rpal" with your function for Problem 3. Your "p3.rpal" should be able to pass the RPAL interpreter. It may help a lot if you try your function in a RPAL interpreter before you hand it in) 4. Problem 4 (25 Points) Implemen t a function "merge" which takes two lists of numbers in increasing order and merges them into one list of numbers in increasing order. For example, merge((1,3,4,7),(2,4,6,7,8)) = (1,2,3,4,4,6,7,7,8). Test your program in an interpreter (No need to submit a .rpal file) 2...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

Homework3 - Now please implemen t an RPAL function...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online