IT5502

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Roll No.

ANNA UNIVERSITY (UNIVERSITY DEPARTMENTS)

B.E. / B. Tech / B. Arch (Full Time) - END SEMESTER EXAMINATIONS, JAN/FEB 2022

INFORMATION TECHNOLOGY
Fifth Semester (V)
IT5502 & Compiler Engineering

(Regulation 2019)
Time: 3hrs Max.Marks: 100

CO 1 Understand the concept of lexical analysis and construction of deterministic and non-

deterministic automata.

CO 2 Understand the concept of parsing and construction of parser.

CO 3 Develop an Intermediate Code generator.

CO 4 Study programming language design, target machine design and run time environment

of compilers.

CO 5 Study about the compiler construction tools.

CO 6 Obtain knowledge to construct a prototype compiler for a subset of a programming

language.

BL – Bloom’s Taxonomy Levels


(L1 - Remembering, L2 - Understanding, L3 - Applying, L4 - Analysing, L5 - Evaluating, L6 - Creating)

PART- A (10 x 2 = 20 Marks)


(Answer all Questions)

Q. No Questions Marks CO BL
1 Draw a DFA for the language accepting strings ending with „10‟ 2 CO1 L5
over input alphabets ∑={0, 1}.

2 Find the Regular Expression corresponding to given statement, 2 CO1 L4


subset of {0,1}*. The Language of all strings containing at least
two 0‟s in the beginning, at least one 1 in the middle and at least
one 0 at end.

3 For the block-structured C code, indicate the values assigned 2 CO6 L3


to w,x,y and z.
int w,x,y,z;
int i = 6; int j = 3;
{
int i = 4;
w = i + j;
}
x = i + j;
{
Int j = 5;
int i = 2;
y = i + j;
}
z = i + j;

4 List at least four commonly used compiler construction tools. 2 CO5 L1

5 Consider the context-free grammar: 2 CO2 L3


S-> +SS | *SS | a
Write the left most derivation and right mot derivation for the string
++*+aaa

6 Eliminate left factors and left recursion in the following grammar 2 CO2 L3
for boolean expressions.
bexpr → bexpr or bterm∣ bterm
bterm → bterm and bfactor∣ bfactor
bfactor →not bfactor∣ (bexpr)∣ true∣ false

7 Differentiate L-attributed SDD from S-attributed SDD. 2 CO3 L4

8 Translate the arithmetic expression a*-b + ( b*c ) into Quadruples, 2 CO3 L3


Triples and Indirect Triples.

9 What are the issues in the design of a code generator? 2 CO4 L1

10 Construct DAG for the basic block: 2 CO4 L3


a=c*f
b=e+d
d=c*f
c=d-b

PART- B (5 x 13 = 65 Marks)
(Restrict to a maximum of 2 subdivisions)

Q. No Questions Marks CO BL
11 (a) (i) Construct NFA for the following regular expression and apply 9 CO1 L3
subset construction method to convert into DFA.
(a | b) ab (a|b)*

(ii) Construct the minimum-state DFA.for the DFA obtained in 11a)(i). 4 CO1 L3

OR

11 (b) (i) Construct DFA for the following regular expression without 9 CO1 L3
constructing NFA.
( a | b )* a b ( a | b )* #

(ii) Signed numbers are strings such as +1280, -31.67, +2.336E5 or - 4 CO1 L3
3.76E-3.
a) Give the regular definitions for the above mentioned strings.
b) Draw the state transition diagram for the signed numbers

12 (a) (i) Explain the phases of a Compiler and write down the output of 9 CO6 L2
each phase for the expression a := b + c * d / 3.
(ii) Identify the lexeme that make up the tokens in the following 4 CO1 L2
program segment. Indicate the corresponding token and pattern.

int checkPrimeNumber(int n)
{
int i, flag = 1, squareRoot;
squareRoot = sqrt(n);
for (i = 2; i <= squareRoot; ++i)
{
if (n % i == 0)
{
flag = 0;
break;
}
}
return flag;
}
OR
12 (b) (i) Write a Lex program that recognizes the tokens such as: if, then, 9 CO6 L4
else, while, relop, id and num.

(ii) Brief about Buffer pairs. What is the use of Sentinels in it? 4 CO1 L2

13 (a) (i) Devise predictive parser and show the parsing table for the 13 CO2 L3
following grammar:
S-> a | (R)
T-> S, T | S
R-> T
Check whether the given string “(a, (a,a))” belongs to the above
grammar.

OR
13 (b) (i) Construct a CLR parser for the following grammar: 13 CO2 L3
S →Ta | bTc |Xc | bXa
T→e
X→e
Parse the string “eaaaa” using the above grammar.
Check whether the given grammar is LALR(1)

14 (a) (i) Write the SDD with semantic actions for generating three address 9 CO3 L3
code for array references and translate the following assignment.

y = c[i][j] + d[i]+ a

(ii) With the proper L-attributed definition, draw a dependency graph 4 CO3 L3
for the following statement:
10 + 5 - (3 +7)

OR

14 (b) (i) Write the semantic actions for the translation of Expressions and 9 CO3 L3
translate the following expression to generate the three address
code using annotated parse tree:
x = a + b + (- d + - e)
(ii) Show the steps of constructing the syntax tree and DAG for the 4 CO3 L3
expression:
(a+b) - ((a+b) *(a-b)) + (a+b)

15 (a) (i) Explain how Peephole optimization can be applied to improve the 8 CO4 L2
intermediate code with an example for each of the characteristics
of optimization.

(ii) Generate intermediate code and target code for the expression 5 CO4 L4
x = (a-b) +(a+c)
OR
15 (b) (i) Assume the matrix entries are numbers that require 4 bytes, and 8 CO4 L4
that matrices are stored in row-major order.

Generate three address code and draw the flow graph for the
following code:

for (i = 1; i < n; i++)


{
key = arr[i];
j = i - 1;
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}

(ii) Optimize the three address code obtained from 15 (b)(i) by 5 CO4 L4
preserving the semantics of the original program.

PART- C (1 x 15 = 15 Marks)
(Q.No.16 is compulsory)

Q. No Questions Marks CO BL
16. (i) What is the intended use of short circuit code? 10 CO3 L5
Write the required Syntax Directed Definition and translate into
three address code for the statement:

if( a<b && b<d || e==f && c<d)


x=1 ;

(ii) Apply batckpatching to generate code for the same statement in 5 CO3 L3
one pass.

You might also like