0% found this document useful (0 votes)
12 views

IT340 - Programming Language Design Concepts3

The document is an exam paper for a programming language design concepts course. It contains 3 questions testing knowledge of programming language principles, logic programming concepts and applications, and Python list, string and tuple manipulation.

Uploaded by

jathurshanm3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

IT340 - Programming Language Design Concepts3

The document is an exam paper for a programming language design concepts course. It contains 3 questions testing knowledge of programming language principles, logic programming concepts and applications, and Python list, string and tuple manipulation.

Uploaded by

jathurshanm3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Sri Lanka Institute of Information Technology

B.Sc. Honours Degree in Information Technology


Specialized in Information Technology

Final Examination
Year 3, Semester 1 (20 19)

IT340 - Programming Language Design Concepts


Duration: 3 Hours

June 2019

Instructions to Candidates:

+ This paper has 3 questions.


+ Answer all questions in the booklet given.
+ The total marks for the paper is 100.
+ This paper contains 6 pages, including the cover page.
+ Electronic devices capable of storing and retrieving text, including
calculators and mobile phones are not allowed.

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)

c) Draw syntax graph for the following BNF grammar rules.


a.) <expr> ::=<factor> <opr> <expr> I <factor> ( -J. marks)

b) <digits> -7 <digit > I <digits> ( -J. marks)

2
Question 2 (40 Marks)

a) Write four features of pure logical programming languages (4 marks)

b) State four applications of logic programming (4 marks)

c) Given the following kno\vledge base :

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).

\Vatches(X. Y) :- likes(X. Z). film (Y. Z).

(i) Determine the output of the following queries


a. ? dog (X) .
b. ? likes ( aravinda, pradeepa
c. ? likes I X, mystery)
:::i. ? o"Jatches ( kamal , harrypo~er I
)

e. ? likes(kama_:_, \
~y~

~ I

( 5 marks)

4
(ii) Defme a rule called animal()

e.g. animal (X)

X is an animal

Hint : x. is either a cat or a dog (4 marks)

(iii) Define a rule called likecats()

e.g. likecats (X)

X likes cats

Hint: Pradeepa likes Kitty (4 marks)

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).

owns(mary, Pet):- cat(Pet), black_spots(Pet)


loves(Who, What) :-owns(Who, What). (5 marks)

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 \ = ,- .

I. ?-female (Amy). (2 marks)


II. ?- brotherof (anthon) .X). (2 marks)
III. '?- parentot1ogden.johnette) (2 marks)
IV. '?- siblingof(Y Johnette) (2 marks)
V. '?- male(X) (2 marks)
VI. '?- parentof( ogden. bruce). (2 marks)
VII. '? -brotherof{X. johnctte) (2 marks)

5
Question 3 (20 marks)

a) Write the output ofthe following statements considering


S =[·Minion·. 'Dora·. 10. 4587] (5 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)

B ='programming language design concepts'

a)8[-5]

b)8[1 : -1]

c)8[0] + 8[12] + 8[21] +8[28]


d) 8 [0]
e)8[2:5]

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)

Eg: half list ( [8, 2, 16], list) -7 /ist=/4, 1, 8]

End of the Question Paper

You might also like