2006 Paper 6 Question 6
Compiler Construction
(a) Describe a difference and a similarity between the notions of overloading and
polymorphism. [2 marks]
(b) Define the notion of type safety in a programming language. [2 marks]
(c) Describe the linking phase and the difference between static and dynamic
linking. [2 marks]
(d) Suppose that a programming language allows nested functions. How might a
stack-based implementation of f access the value associated with a?
int g(int a)
{
int f(int x) {
return a + x;
}
…
f(2);
…
}
[4 marks]
(e) Describe the low-level code that could be generated by compiling the following
code fragment for a stack-based target machine.
int f(int a, int b)
{
int z = a * b;
return a + z;
}
…
f(1, 2) * f(3, f(4, 5));
…
[10 marks]