

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Bermudez; Class: PROGRAM LANG CONCEPTS; Subject: COMPUTER PROGRAMMING; University: University of Florida; Term: Spring 2009;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


nd
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: