IT 340-Programming Language Design Concepts7
IT 340-Programming Language Design Concepts7
Duration: 3 Hours
Instruction to Candidates:
• There are four questions available.
• Total Marks 100.
• This paper c\mtains 7 pages with Cover Page.
• This is a close book examination.
Question 1 (25 marks)
a) Briefly explain the structured program principle and an example where it get violated in
FORTRAN.
(3 marks)
b) Write a simple lex & yacc program to develop a syntax checker to identify a simple
java program as given below.
class Exercise{
public static void main(String args[]) {
int num = 34;
} '
(10 Marks)
c) Consider the BNF grammar to define some arithmetic expressions and write the answer
for parts given below.
i) Draw syntax graph for the following BNF grammar rules. (2 marks)
ii) Show a parse tree and leftmost derivation for the following statement.
(6 marks)
x +(z-y)
Page 2 of7
Question 2 (30 marks)
a) Compare and contrast the procedural paradigm and the functional paradigm.
(3 marks)
c) Write a f).mction to determine if the person is an adult or not when the age is given.
(3 marks)
Example: (adult? 3 5) Should return T
d) Using the scheme function definition given below answer the questions.
COND
((NULL? lst) ' ())
(ELSE (CONS (fun (CDR lst ) ) ( CAR lst ) )
) )
ii) What will be the output when the function is executed with
\
(fun (32 19 45 90)) (2 marks)
e) Write a scheme function to find the last element in the list and return the square value
of the last element.
Example:last (3 10 78 5) shouldreturn25 (4marks)
Page 3 of7
f) Write a scheme function to create a list containing integers when the lower bound and the
upper bound is given.
Page 4 of7
Question 3 (30 marks)
b) Consider the following rules and facts. Find the goal "loves(Who, What)." using
backward chaining.
Facts:
Fl: cat(fubby).
F2: black_spots(fubby).
F3: dog(figaro).
F4: white_spots(figaro).
F5: black_spots(toby).
Rules:
Rl: owns(mary, Pet):- cat(Pet), black_spots(Pet).
R2: loves(Who, What):-owns(Who, What).
(4 marks)
c) Write a prolog function to return the element before the last element ofthe list.
Example: last_but_one (X, [26, 12, 10, 88, 67] )X should return 88
(4 marks)
d) Write a prolog function to rotate elements to the left in the list.
Example: rotatelist ([10,22,65,50],R) Rshouldreturn
[22, 65, 50, 10]
(5 marks)
Page 5 of7
g) 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).
parent?f(amy,bruce).
parentof(ogden,johnette).
parentof(ogden,anthony).
parentof(ogden,bruce).
siblingof(X,Y) :- parentof(Z,X),parentof(Z,Y),X \=Y.
brotherof(X,Y) :- parentof(Z,X) ,male(X),parentof(Z,Y),X \=Y.
(4 marks)
1. ?-female (Amy).
2. ?- brotherof (anthony, X).
3. ?- paren tof (ogden, j ohnet te) .
4. ?-siblingof(Y,johnette).
Page 6 of7
Question 4 (15 marks)
a) Consider the tuple Tup = ("Kandy", 20.5, 87,"10.7") in python and provide answers for
the following questions.
(2 marks)
i) Write a statement to print all the elements starting from the second element.
ii) Write a statement to modify the value 87 so it's value is increased by two.
b) Find the output generated by the Python interpreter for the following expressions.
(3 marks)
i) -11 % 3
ii) 35 I 2 * 3 % 3
iii) 167 II 4
c) Write a python function called sum to calculate the sum when the list is passed as a
parameter. Call the function and display the result. (5 marks)
d) Write a python class called Rectangle which has a function called "getArea". The getArea
function should accept width and length as parameters and return the area of the rectangle.
Create an object from the Rectangle class and call the "getArea" method.
(5 marks)
Page7of7