Programming Language Concepts - Homework 2 | COP 4020, Assignments of Computer Science

Material Type: Assignment; Professor: Bermudez; Class: PROGRAM LANG CONCEPTS; Subject: COMPUTER PROGRAMMING; University: University of Florida; Term: Spring 2009;

Typology: Assignments

Pre 2010

Uploaded on 09/17/2009

koofers-user-exl
koofers-user-exl ๐Ÿ‡บ๐Ÿ‡ธ

3

(2)

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COP4020- Programming Language Concepts
Spring- 2009
Homework # 2
Due Date: 22nd April, 2009 at 11:59 PM
1) Consider the following pseudocode, assuming nested subroutines and
static scope:
procedure main
g : integer
procedure B(a : integer)
x : integer
procedure A(n : integer)
g := n
procedure R(m : integer)
write integer(x)
x /:= 2 โ€“โ€“ integer division
if x > 1
R(m + 1)
else
A(m)
โ€“โ€“ body of B
x := a ร— a
R(1)
โ€“โ€“ body of main
B(3)
write integer(g)
a) What does this program print?
b) Show the frames on the stack when A has just been called. For
each frame, show the static and dynamic links.
2) Consider the following pseudocode:
x : integer โ€“โ€“ global
procedure set x(n : integer)
x := n
pf2

Partial preview of the text

Download Programming Language Concepts - Homework 2 | COP 4020 and more Assignments Computer Science in PDF only on Docsity!

COP4020- Programming Language Concepts

Spring- 2009

Homework # 2

Due Date: 22

nd

April, 2009 at 11:59 PM

1) Consider the following pseudocode, assuming nested subroutines and static scope:

procedure main g : integer

procedure B(a : integer) x : integer

procedure A(n : integer) g := n

procedure R(m : integer) write integer(x) x /:= 2 โ€“โ€“ integer division if x > 1 R(m + 1) else A(m)

โ€“โ€“ body of B x := a ร— a R(1)

โ€“โ€“ body of main B(3) write integer(g)

a) What does this program print?

b) Show the frames on the stack when A has just been called. For

each frame, show the static and dynamic links.

2) Consider the following pseudocode:

x : integer โ€“โ€“ global

procedure set x(n : integer) x := n

procedure print x write integer(x)

procedure first set x(1) print x

procedure second x : integer set x(2) print x

set x(0) first() print x second() print x

What does this program print if the language uses static scoping? What does it print with dynamic scoping? Why?

3) Extend the example shown in class, Lecture 17, slides 22-26, by defining

predicates for:

  • GrandMotherOf(X,Y)
  • GrandFatherOf(X,Y)
  • UncleOf(X,Y)
  • Aunt(X,Y)
  • CousinOf(X,Y)