Give a program which gives different results according to whether dynamic

Present a right-most derivation for the string (a, ((a, a), (a, a)))
March 21, 2023
Explain how a parse tree representing an expression can
March 21, 2023

Give a program which gives different results according to whether dynamic

2005 Paper 6 Question 5
Compiler Construction
(a) Give a program which gives different results according to whether dynamic or
static binding is used. [3 marks]
(b) Summarise two different methods of implementing functions which have free
variables statically bound in an outer nested function, paying particular
attention to (i) the lifetime of any storage used and (ii) any language
restrictions which the implementation requires. Note also, for each case, what
the effect is of assignment to such free variables, e.g. when calls to g() and
h() are interleaved in
f(int x)
{ int a = x+7;
int g() { a++; }
int h(int y) { return a+y; }

}
[8 marks]
(c) Give a program in which a function is called recursively without any value or
function being defined recursively. [3 marks]
(d) Give a program which produces three distinct results according to whether
parameters are passed by value, by reference, or by value-result. [3 marks]
(e) Explain the likely storage layouts for Java objects p and q respectively of classes
P and Q defined by
class P { int a,b; int f() { <body1> } }
class Q extends P { int c; int f() { <body2> }
int g() { <body3> } }
[3 marks]