CSC 8310 Linguistics of Programming Languages
1. (5 points) In Prolog, assume that you have a number of
facts of the form:
Dr. David Matuszek
Fall 1997, Villanova University
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:
(Notice that the procedure prints a number before the main program does.)
A = 2
call foo (A, A + 5)
procedure foo (X, Y)
X = X + 3
print X * Y
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?
3. (2 points) In Lisp,
 an S-expression is either an atom or a list, and
 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.