Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

Programming Language Design Concepts-IT340 9

The document discusses programming language design concepts and contains four questions. Question 1 covers topics like lex and yacc programs, BNF grammar rules, and ambiguity in parsing. Question 2 is about functional programming concepts like referential transparency and Scheme functions. Question 3 covers logical programming in Prolog including features, predicates, and knowledge bases. Question 4 discusses multi-paradigm programming with Python.

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)
26 views

Programming Language Design Concepts-IT340 9

The document discusses programming language design concepts and contains four questions. Question 1 covers topics like lex and yacc programs, BNF grammar rules, and ambiguity in parsing. Question 2 is about functional programming concepts like referential transparency and Scheme functions. Question 3 covers logical programming in Prolog including features, predicates, and knowledge bases. Question 4 discusses multi-paradigm programming with Python.

Uploaded by

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

00284

==•I=
lit. ,,'' ..
..iii~· 1'J

Sri Lanka Institute of Information Technology

B. Sc. Special Honours Degree in


Information Technology

FinalExamination
Year 3, Semester 1 (2016)

IT340 - Programming Language Design Concepts

[ 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

Question 1 -Meta Language (25 Marks)

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;

• Names, numbers angle brackets "*" and "="


• Each statefuent terminates with a special character "*"
I

• Each part is separated with a "="sign


• Name consists of any sequence of uppercase or lower case letters
• Numbers consist of any sequence of digits in the range 0 to 5
• Order of an expression is names, number, angle brackets, names.

Valid expression example;

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

Question 2 - Functional Programming Paradigm 30 Marks)

a) What is referential transparency? (2Marks)

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

c) Convert the following mathematical expression to scheme. (5 Marks)


-b + sqrt('sqr(b)- 4*a*c)) I 2a

d) Write a scheme function to calculate occurrence ofnumber five in a list of numbers.


(6 Marks)
Eg:(noOfFive '(57 0 985 65))-7 3

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)

Eg: multiply_list' (2 5 9) should return 90

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

Question 3 - Logical Programming Paradigm (30 Marks)

a) Write four features of pure logical programming languages (2 Marks)

b) Write a prolog function called min_valthat returns the minimum of a list of numbers.
(6 Marks)

Eg:min_va1([9, 7, E, 2], X)X=2

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)

Eg:cube_1ist ([1, 2, 3] , list )-7 list=[1,8,27]

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)

Eg; lexless ( [1, 14], [1, 14, 20]) -?True


1 ex 1 e s s ( [ 14 , 15 , 2 0 ] , [ 7 , 15 , f 5 , 4 ] ) -7 False

23/04/2016
00284

e) Given the following knowledge base :

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

movie_actor(A) :- male(A), acted(A,B), movie(B).

i) Determine the output of the following queries (5 Marks)


1) ?acted(X,thor}.

2) ? female(X).
3) ?acted(chris,X).
4) ? movie_actor(A).
5) ?movie_actor(ryan).

ii) Define a rule to identify a movie actress. (2 Marks)


Hint: If X is acted in a movie and a female X should be a movie actress

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)

a) Write 4 major advantages of Python programming language. (2 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:

Enter first Number - 1.5


Enter second Number- 6.3
The sum of 1.5 and 6.3 is 7.8

End of the Question Paper

23/04/2016

You might also like