Programming Language Design Concepts-IT 340 8
Programming Language Design Concepts-IT 340 8
Information Technology
Final Examination - June
Year 3, Semester 1 (20 17)
Duration: 3 Hours
Instruction to Candidates:
• There are four questions available.
• Total Marks \00.
• This paper contains 7 pages with Cover Page.
• This is a close book examination.
Question 1 (25 marks)
b) Write a simple lex & yacc program to develop a syntax checker to identify a simple
switch case as given below.
switch (month) {
case 1: print ();
break;
default: print ();
break";
( 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 rule. (2 marks)
<identifier> ::= AI B I C
ii) Show a parse tree and leftmost derivation for the following statement.
(6 marks)
A = A + (B + C)
Page 2 of7
Question 2 (30 marks)
c) Write a function to determine the maximum from two given numbers. (3 marks)
Example: (max? 80 23) should return 8 0
d) Using the below given scheme function definition answer the questions.
(define (y s lis)
(cond
((null? lis ) '() )
((equal? s (car lis)) lis)
(else ( y s (cdr lis)))
) )
,_
ii) What will be the output when the function is executed with
Page 3 of7
e) Write a scheme function to get the last element in the list.
Example: last '(3 10 78 59) should return 59 (4 marks)
t) Write a scheme function to calculate how many zero values are there in a list of numbers.
Example: (zero '(45 0 67 90 0 3)) shouldreturn2 (5 marks)
g) Write a scheme function to remove the searching element from the list. It should returns
a new list with all occurrences of the searching element removed.
Hint: you can use eqv function in scheme to compare two elements are equal or not.
Example: (removeall 1
a 1
(a b b d a)) should return (b b d)
(6 marks)
Page 4 of7
Question 3 (30 marks)
b) Consider the following rules and facts. Find the goal "sister (alice, Z) "using backward
chaining.
Facts:
Fl: male(' albert').
F2: male(edward).
F3: female(alice).
F4: female(victoria).
F5: parents(edward, victoria, albert).
F6: parents(alice, victoria, albert).
Rules:
Rl: IF female(X) AND parents(X, M, F) AND parents(Y, M, F) THEN sister(X, Y).
(5 marks)
d) Write a pro log function to count the number of an occurrence appear in the list.
Page 5 of7
t) Given the following knowledge base and find the output of the following queries.
vegetarian(jose).
vegetarian (james).
vegetable( carrot).
vegetable(egg_plant).
likes(jose, X) :- vegetable(X).
loves(Who, egg_plant) :- vegetarian(Who).
(7 marks)
1. ?- vegetable(X).
2. ?- vegetable(potato).
3. ?- vegetarianU.
4. ' ?- likes(jose, _).
5. ?- likes(Who, egg_plant).
6. ?- loves(Who, egg_plant).
7. ? - vegetable(Carrot).
Page 6 of7
Question 4 (15 marks)
a) Consider the given key value pairs and provide answers for following questions.
(3 marks)
Key Value
Color Red
Food Burger
Drink Milk
Fruit Banana
b) Find the output generated by the Python interpreter for the following expressions.
(3 marks)
i) 13//4
ii) 20/2**3*4
iii) -6%4
c) Write a program to take a word as the user input. Then count the number of times that the
letter 'a' and letter 'e' are appearing within the word entered and display the result.
(4 marks)
d) Write a python class called phone which has a function "Ring". The Ring method should
display a message indicating that phone is ringing. Create an object from the phone class
and call the ring method.
(5 marks)
Page 7 of7