# hwk3 - RPAL function called "power" to achieve...

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

COP 5555 Programming Language Principles Homework 3 Assigned: May 31, 2010 Deadline: 11:59pm Jun. 7, 2010 *Note: Please submit your solution to the e-learning system by the deadline. No late submission is allowed. 1 Problem 1 Using the RPAL string-to-tree-transduction grammar, draw the abstract syntax tree (if possible) for each of the following programs : (b) x or y -> z -> x | y | x (c) x aug y , z , p (d) x , y , z aug p (e) let f (x) = x ** 2 - 1 in f (y) where y = 4 (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 In problem 1, the structure of each program is not apparent because the program is written on a single line as a linear string. Re-write each program on several lines, indenting appropriately to re ect the structure. 1

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

View Full Document
3 Problem 3 The integer operator "**" in RPAL raises an integer to an integer power. Now please implement an
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: RPAL function called "power" to achieve the same functionality. For example (power 3 2) returns the same value as (2**3), which is 8. Your function should use the fact that x 2 n = ( 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 helps a lot if you try your function in a RPAL inter-preter before you hand it in) 4 Problem 4 Implement 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). (Note: You can assume the input lists are always in increasing order. Please submit a separate "p4.rpal" with your function for Problem 4. Your "p4.rpal" should be able to pass the RPAL inter-preter.) 2...
View Full Document

## This note was uploaded on 01/22/2012 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.

### Page1 / 2

hwk3 - RPAL function called "power" to achieve...

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

View Full Document
Ask a homework question - tutors are online