Programming Language Design Concepts-IT340 9
Programming Language Design Concepts-IT340 9
==•I=
lit. ,,'' ..
..iii~· 1'J
FinalExamination
Year 3, Semester 1 (2016)
[ Duration: 3 Hours
Instruction to Candidfites:
•!• There are four qpestions available.
•!• Total Marks 100
•!• This paper contains eight pages with Cover Page.
23/04/2016
00284
a)
i) What will happen after Lex and Yacc file compilation (2 Marks)
ii) Write a simple lex & yacc program to identify a language which consist of
following;
Edward=0513=<>=Cullen=*
Ryan= 1432=<>=reynoldsdeadpool=*
Superman=2002=<>=Henrywilliams=*
Additional Support:
Writing the relevant lex program which identifies each required category will be
sufficient.For the yacc program identifying the above given pattern will be
sufficient. (12 Marks)
b) Write set of BNF Prarnrnar rules for the following Pascal do-while loop (4 marks)
while number > 0 do
begin
sum := sum + number;
number . number -2;
end;
23/04/2016
00284
c) Write the leftmost derivation and the right most derivation for theprovided example B =
A+C*Bwith respect to the following grammar. (4 marks)
<assign>~<id> <expr>
<id>~ A I B I C
<expr>~<expr> + <term> I <term>
<term>~<term> * <factor> I <factor>
<factor>~ ( <expr> ) I <id>
d) Comment about the ambighity of, the statement with possible parse trees. (3 marks)
23/04/2016
00284
b) Write a scheme function find_first to find the first element of a list. (4 marks)
Eg: (find_first '(7 6 3 9 1)) should return 7
e) Write a Scheme function called mul tiply_listthat takes a simple list of numbers as
input and returns the multiplication of the numbers. (6 Marks)
t) Using the below given scheme function definition answer the questions
(define (mystryCalc n)
(cond ((=nO) 0)
(else (+ n (mystryCalc(- n 1))))
- )
.
i) What doe,s this Scheme function do? Explain briefly. (3 Marks)
ii) What will be the output when the function is executed with (4 Marks)
1. (mystryCalc 6)
2. (mystryCalc 10)
23/04/2016
f 00284
b) Write a prolog function called min_valthat returns the minimum of a list of numbers.
(6 Marks)
c) Write a prolog function called cube_1istthat takes a list as input and returns a list
which contains the cube value of each of the elements in the original list. (6 marks)
d) Lexicographic order is like the order of words in a dictionary. Based on the ordering of
letters (Athrough Z), words are sorted alphabetically. If one word is a prefix of another,
the shorter wordcomes first, so the word "an" comes before "ant".
For this question~ we'll use lists instead of words, and we'll use integers instead of letters.
Write a Prolog predicate lex1ess that takes two lists of integers and is true if its first
argument is(strictly) lexicographically less than the second argument. (6 marks)
23/04/2016
00284
movie(deadPool).
movie(twilight).
movie(thor).
movie(avengers).
melodrama(bOF).
melodrama(heirs).
male(ryan).
male (robert) .
male(chris).
male(lee).
male ( joon) .
female(kristen).
female(natalie).
female(scarllet).
female(gina).
female(shin).
acted(joon, bOF).
acted (lee, bOF) .
acted(lee, heirs).
acted(shin, heirs).
acted(ryan, deadPool).
act~d(gina, deadPool).
acted(robert, twilight).
acted(kri;5ten, twilight).
acted(chris, thor).
acted(natalie, thor).
acted(chris, avengers).
acted(scarllet, avengers).
acted (lee, bOF) .
directed(joss, avengers).
23/04/2016
I 00284
directed(bill, twilight).
directed(timm, deadPool).
directed(kenneth, thor).
2) ? female(X).
3) ?acted(chris,X).
4) ? movie_actor(A).
5) ?movie_actor(ryan).
iii) Define a rule to find out the director of the movie "avengers" (3 Marks)
23/04/2016
Question 4 - Multi Programming Paradigm (15 Marks)
b) Write the output of the following statements considering S =['rolex, 'tissot', SO, 4587)
(3 Marks)
i) S[-3]
ii) S[l :-1]
iii) S[2] +55
iv) 2*S[:3] + ['casio]
c) Write a python program to check a number that user enters and output whether that number
is a positive negative or zero. (5 Marks)
d) Write a python program to add and print three numbers that user enters. (5 Marks)
Your output should look like:
23/04/2016