Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
17 views7 pages

Programming Language Design Concepts-IT 340 8

The document contains a past exam paper for a Programming Language Design Concepts course. It has four questions covering topics like FORTRAN issues, lex and yacc programs, BNF grammars, functional programming in Scheme, Prolog programs and queries, and Python programming concepts.

Uploaded by

jathurshanm3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

Programming Language Design Concepts-IT 340 8

The document contains a past exam paper for a Programming Language Design Concepts course. It has four questions covering topics like FORTRAN issues, lex and yacc programs, BNF grammars, functional programming in Scheme, Prolog programs and queries, and Python programming concepts.

Uploaded by

jathurshanm3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

/

Sri Lanka Institute of Information Technology

B. Sc. Special Honours


.
Degree
Ill

Information Technology
Final Examination - June
Year 3, Semester 1 (20 17)

IT340 - Programming Language Design Concepts

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)

a) Briefly explain two issues of using the FORTRAN language.


(3 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.

<sentence> ::= <expression>


<expression> ::= <term> I <expression> + <term>
<term> ::= <identifier> I <term> * <identifier> I ( <expression> )
<identifier> ::= AI B I C

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)

d) Write the EBNF grammar to the following BNF grammar below.


i) <expr> : := <digits> I empty

ii) <id> ::= <letter> I <id> <letter> I <id> <digit>


(4 marks)

Page 2 of7
Question 2 (30 marks)

a) Select the correct statement /s regarding the functional paradigm. (3 marks)


1. Functional programming languages support flow Controls.
11. Functional programming supports lazy evaluation features.
m. Functional programming manipulate variables by accessing the memory
locations directly.
IV. Focus on language expressions evaluation rather than a sequence of statements.
v. Closely related to the design of conventional computer- the Von Neumann
design.

b) Convert the following mathematical expression to scheme. (4 marks)


3 + 10 % 4 - 2 I 1

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)))
) )
,_

i) What does this Scheme function do? Explain briefly. (3 marks)

ii) What will be the output when the function is executed with

(y '1 '(117141)) (2 marks)

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)

a) Briefly describe the structure of a Pro log Program (3 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)

c) Write a pro log function to find the power value. (4 marks)


Example: pow ( 3, 3, z) Z should return 2 7

d) Write a pro log function to count the number of an occurrence appear in the list.

Example: occurrence (2, [5,10,2,3,52,6,2],P) Pshouldreturn3


(5 marks)

e) Develop a Prolog Program to identify if a word is a palindrome. (Palindrome is a word


that reads the same backward as forward is consider a palindrome word. Eg. noon is a
palindrome word)

Example: palindrome ( [n, o, o, n]) Should return yes


'~
(5 marks)

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

i) Construct a dictionary to store.the above details.


ii) Write a statement to delete the "Food- Burger" record from the dictionary.
iii) Write a statement to insert a new key values as "Animal- Dog".

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)

***End of Exam Paper***

Page 7 of7

You might also like