IT340 - Programming Language Design Concepts3
IT340 - Programming Language Design Concepts3
Final Examination
Year 3, Semester 1 (20 19)
June 2019
Instructions to Candidates:
1
Question 1 (35 Marks)
a) State the Zero-One-Infinity programming principle and specify an example \\here the principle
has been \'iolated with an example
(5 Marks)
b) Write the BNF grammar for the following Syntax graphs. (6 Marks)
i)
ii)
2
Question 2 (40 Marks)
dog (tony).
dog (rosy) .
cat (kitty).
cat (fluffy).
person(sujeepan).
person(amali).
person(binthuran).
person (dinuka).
person(perera).
film(mi3, action).
film(davinchicode, mystery).
film(harrypoter, children).
film(doom, action).
likes(aravinda, amali)
likes (aravinda, tony).
likes(aravinda, mystery).
likes (pradeepa, kitty).
likes (pradeepa, action) .
likes(sujeepan, mystery)
likes(kamal, fluffy).
likes (kamal, tony).
likes(kamal, children).
e. ? likes(kama_:_, \
~y~
~ I
( 5 marks)
4
(ii) Defme a rule called animal()
X is an animal
X likes cats
d) Consider the following rules and facts. Find the goal ··loves( Who. What) ...
cat ( fubby) .
black_spots(fubby).
dog (figaro).
white_spots(figaro).
black spots(toby).
e) Given the following knowledge base and find the output of the following queries
female (amy).
female(johnette)
male(anthony).
male(bruce).
male (ogden) .
parentof(amy,johnette).
parentof(amy,anthony).
parentof(amy,bruce).
parentof(ogden,johnette).
parentof(ogden,anthony).
parentof(ogden,bruce).
Siblingof(X,Y) :- parentof(Z,X) ,parentof~z,·r: ,){ \~
brother of (X, Y ) : - parent of ( Z , X) , rna l e ( X ) , parent of ( Z , -~ ; , X \ = ,- .
5
Question 3 (20 marks)
i. s [-3]
ii. S[l : -1]
iii. S[2] +55
i v. 2 *S [ : 3 ] + [ 'N emo' ]
v. s [ 0]
b) Consider the declared string and ans\\ er the following questions. (5 marks)
a)8[-5]
b)8[1 : -1]
c) Consider the tuple Tup = ("Kandy ... 20.5. 87 ... 10.7'") in python and provide answers for the
Following questions.
I. Write a statement to print all the elements starting from the second element. ( 3 marks)
II. Write a statement to modify the \alue 87 so that ifs Yalues is increased by t\\O.
(2 marks)
d) Write a prolog function called half list that takes a list as input and returns a list which
Contains the halves of each of the elements in the original list. (5 marks)