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

Material Type: Exam; Class: PROGRAM LANG CONCEPTS; Subject: COMPUTER PROGRAMMING; University: University of Florida; Term: Spring 2008;

Typology: Exams

Pre 2010

Uploaded on 09/17/2009

koofers-user-ts1
koofers-user-ts1 🇺🇸

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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)