Académique Documents
Professionnel Documents
Culture Documents
Instructions:
1) Write all answers on this examination paper.
2) Write your name and student number on this page.
3) Attempt question 1 and any 6 of questions 2 through 8.
4) The paper totals 70 marks.
5) No examination aids, specifically no electronic devices such as calculators,
cell phones, electronic dictionaries; or paper dictionaries are permitted. Use
or possession of unauthorized materials will automatically result in an award
of zero for this examination (this regulation does not preclude special
arrangements being made for students with disabilities). (FHB 5.1.2.A).
6) A mark of 40% must be achieved on this examination in order to obtain a
passing grade in the course.
2 10
3 10
4 10
5 10
6 10
7 10
8 10
Tot al 70
COSC 2P05 Apr. 11, 2016 Page 2 of 10
[5x2] 1. In one or two sentences each, define or explain five of the following terms or concepts as
they pertain to the principles of programming languages.
a. orthogonality
b. attribute grammar
c. binding
d. associative array
e. referential transparency
f. encapsulation
g. dynamic dispatch
COSC 2P05 Apr. 11, 2016 Page 3 of 10
[2] 2b. What is the difference between a free union and a discriminated union? What is the effect
on type safety of having free unions in the language (a la C & C++)?
COSC 2P05 Apr. 11, 2016 Page 4 of 10
[2] 3a. What is the difference between a pointer type and a reference type?
[2] 3b. Why are languages that use reference types generally more type-safe than those that use
pointers?
[2] 3e. Why do dangling pointers occur in C++ but not in Java?
COSC 2P05 Apr. 11, 2016 Page 5 of 10
4. In the following code written in C-like syntax, what is the value of x after the call to the
subroutine f
static int x, z;
void f ( int y ) {
x = 0;
if ( y > z ) y = 1;
else y = 3;
};
void main ( ) {
z = 1;
x = 2;
f(x);
};
[2] 5a. What is the difference between the static link (static chain) and the dynamic link
(dynamic chain) in the activation record (ARI) stack?
draw the layout of the ARI stack at the point marked 1 above. Draw the links as arrows
and divide the ARIs with a bold line. Label the ARI on the left with the routine name.
routine use link var
s local 1 w
[2] c. Draw the path for a reference (at point 1 above) to the variable w.
COSC 2P05 Apr. 11, 2016 Page 7 of 10
[2] 6b. What is the difference between a lightweight task and a heavyweight task?
[3] 6c. How is cooperation synchronization achieved with message passing as in Ada?
[2] 7a. APL is unusual in that operators all have the same level of precedence. Why do you think
that decision was made in the design of the language?
if ( x = 0 ) {
y = 2;
}
else {
y = 3;
}
[2] 7b. Describe the unexpected result in executing this statement and why it happens
[2] 7.e Describe one way the ambiguity in the dangling else is resolved.
COSC 2P05 Apr. 11, 2016 Page 9 of 10
What is the output of the following function invocation? (Show intermediate steps).
question [2,5,1]
COSC 2P05 Apr. 11, 2016 Page 10 of 10
[5] 8b. Consider a prolog fact parent(A, B), meaning A is the parent of B. It might be used as
follows:
parent(anne, bob).
parent(alex, bob).
parent(ann, bruce).
parent(ann, brenda).
parent(bob, carl).
parent(bob, christie).
parent(brenda, chris).
etc.
Write a Prolog rule that could be used to determine the cousin family relation, using only the
parent/2 facts, as well as the built-in predicate \= for determining when 2 terms cannot unify (be
equal). For example, cat \= dog is true, while dog \= dog is false.
(Hint: For full marks, you will need to use \=.)