



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Read the whole exam first (there are a total of 6 pages) and plan your time. You have 50 minutes to complete all the questions. There are a total of 100 points. The exam is open book, open notes, and closed neighbors. Good luck!
Show the result of evaluating each of the following Scheme expressions:
(a) (car (car โ((a) (b) (c)))) (b) (cdr (cdr โ((a) (b) (c)))) (c) (cons (cons โ(a) โ(b)) โ(c)) (d) (car โ(car โ((a) (b) (c)))) (e) (car (cons (car โ((a) (b) (c))) โ(d))) (f) (cdr (cons โ((a) (b)) (cons โ(c) โ(d)))) (g) (car (cdr (car (cdr โ(((a) (b)) ((c) (d))))))) (h) (car (car (cons โ(quote ((a) (b))) โ((c) (d)))))
Hint: remember that (car (cons a d)) = a and (cdr (cons a d)) = d.
Consider the following grammar for variable and class declarations in Java:
Indicate any problems in this grammar that prevent it from being parsed by a recursive-descent parser with one token lookahead. You can simply circle the offending parts of the grammar above.
Transform the rules for
Given the following C++ class declarations:
class B { private: int x; public: virtual int foo() { return this->bar(); } virtual int bar() { return 1; } };
class C { private: int x; public: virtual int foo() { return 2; } };
class D : public B, public C { private: int y; public: virtual int foo() { return B::foo(); } };
class E : public D { private: int z; public: virtual int bar() { return 3; } };
Show the layout of objects of class E and the contents of the virtual function tables (you can ignore the this-offsets). What are the values assigned to variables i, j, k, and l when the following code is executed?
B * p = new D(); C * q = new D(); B * r = new E(); C * s = new E(); int i = p->bar(); int j = q->foo(); int k = r->bar(); int l = s->foo();