CSC 8310 Linguistics of Programming Languages
Name:_____________________________
Dr. David Matuszek
Fall 1997, Villanova University
Prolog quiz
1. (5 points) In Prolog, assume that you have a number of
facts of the form:
mother(M, C). /* M is the mother of C */
father(F, C). /* F is the father of C */
male(X). /* X is male */
female(X). /* X is female */
Write Prolog rules for
grandmother(G, X). /* G is a grandmother of X */
sister(S, X). /* S is a sister of X */
half_brothers(B1, B2). /* B1 and B2 are male and have the same mother
or the same father, but not both. */
2. (3 points) Consider the following (pseudocode) program:
main program
A = 2
call foo (A, A + 5)
print A
end
procedure foo (X, Y)
X = X + 3
print X * Y
end
|
|
What two numbers are printed if call by value is used?
|
What two numbers are printed if call by reference is used?
|
What two numbers are printed if call by name is used?
|
(Notice that the procedure prints a number before the main program does.)
3. (2 points) In Lisp,
[1] an S-expression is either an atom or a list, and
[2] a list is a left parenthesis, followed by zero or more
S-expressions, followed by a right parenthesis.
Write BNF definitions of S-expression and list
(assume that atom is defined elsewhere). Use "pure"
BNF rather than extended BNF if you can.