Docsity

Sample Exam Solution for Final - Program Language Concepts | COP 4020, Exams of Computer Science

Toggle sidebar
bg1
COP4020 Spring 2008 Sample Exam Solutions
1.
proc T(); proc Ta();
Ta(); N = 1; Tc();
while NT = โ€˜,โ€™ { while NT = โ€˜augโ€™ {
Read(โ€˜,โ€™); Read (โ€˜augโ€™; )
Ta(); Tc ();
N ++; BuildTree (โ€˜augโ€™, 2);
} }
if N > 1 BuildTree(โ€˜tauโ€™, N); end;
end;
proc Tc();
B();
if NT = โ€˜->โ€™ {
Read (โ€˜->โ€™);
Tc ();
Read (โ€˜|โ€™);
Tc ();
BuildTree (โ€˜->โ€™, 3);
}
end;
2.
(1) No, the two lists do not unify. Unifying them would require first that [Y,a] unify with
[a,X]. They do unify, but Y is bound to a, and so is X. Next, Y would have to unify with
b, which it can't, because it is already bound to a. Changing the first list to [ [Y, a], a, c]
would solve the problem.
(2) Uncle(X,Y) :- Parent(W,X), Parent(Z,W), Parent(Z,Y)
pf3

Partial preview of the text

Download Sample Exam Solution for Final - Program Language Concepts | COP 4020 and more Exams Computer Science in PDF only on Docsity!

COP4020 Spring 2008 Sample Exam Solutions 1. proc T(); proc Ta(); Ta(); N = 1; Tc(); while NT = โ€˜,โ€™ { while NT = โ€˜augโ€™ { Read(โ€˜,โ€™); Read (โ€˜augโ€™; ) Ta(); Tc (); N ++; BuildTree (โ€˜augโ€™, 2); } } if N > 1 BuildTree(โ€˜tauโ€™, N); end; end; proc Tc(); B(); if NT = โ€˜->โ€™ { Read (โ€˜->โ€™); Tc (); Read (โ€˜|โ€™); Tc (); BuildTree (โ€˜->โ€™, 3); } end; 2. (1) No, the two lists do not unify. Unifying them would require first that [Y,a] unify with [a,X]. They do unify, but Y is bound to a, and so is X. Next, Y would have to unify with b, which it can't, because it is already bound to a. Changing the first list to [ [Y, a], a, c] would solve the problem. (2) Uncle(X,Y) :- Parent(W,X), Parent(Z,W), Parent(Z,Y)