Roll No. …………………..
TCS–602
B. Tech. (CSE + AI + Cloud)
(Sixth Semester)
EXAMINATION, 2022-23
COMPILER DESIGN
Time : Three Hours
Maximum Marks : 60
Note : Question paper has three Sections. Read carefully
instructions for each Section.
Section—A
(Very Short Answer Type Questions)
1. Attempt all questions. 1 each
(a) Point out any two reasons as to why phases of
compiler should be grouped ? (CO1, BT-RE)
(b) Give the specification of the YACC parser
generator. (CO1, BT-RE)
P. T. O.
[2] TCS–602
(c) Write a brief note on Cross Compiler.
(CO1, BT-RE)
(d) Define CLOSURE (I). (CO2, BT-RE)
(e) Define a Parser. What is the role of grammars in
Parser construction ? (CO2, BT-RE)
(f) List down the conflicts during shift-reduce
parsing. (CO2, BT-RE)
(g) Explain the role of code generator in a compiler.
(CO3, BT-RE)
(h) State the three kinds of intermediate
representation. (CO3, BT-RE)
(i) Write short note on syntactic phase errors.
(CO4, BT-RE)
(j) List out the different storage allocation strategies.
(CO4, BT-RE)
(k) What is the role of code Optimizer in compiler ?
Is it a mandatory phase. (CO5, BT-RE)
(l) Write short note on loop jamming. (CO5, BT-RE)
Section—B
(Short Answer Type Questions)
2. Attempt all questions. Each question carries 4 marks.
(a) Design a DFA for L = {W (a, b)*/Nb’s(W) mod
4 > = 2}. (CO1, BT-UN)
OR
Design a DFA for L = {W (0, 1)*/W mod
5 > = 3}. (CO1, BT-UN)
[3] TCS–602
(b) What is token ? Find the number of tokens in the
following C code and also describe in detail
which one is token in the following C code :
(CO1, BT-AN)
switch(input value)
{
case 1 : b = c * d; break;
default : b = b++; break;
}
OR
Define the compiler phases. Write down the
output for the following expression after each
phase a = b * (c + 60) and also write the number
of tokens in this input. (CO1, BT-AN)
(c) Compute the FIRST and FOLLOW sets for each
non-terminal of the grammar is given below :
(CO2, BT-AN)
S ABa / bCA
A cBCD / E
B CdA / ad
C eC / E
D bSf / a
P. T. O.
[4] TCS–602
OR
What is Operator grammar ? Explain with the
help of example. Construct a operator precedence
parsing table for the given grammar.
(CO2, BT-AN)
E T*E / T
T FT / F
F id
(d) Consider the following code segment :
(CO3, BT-AN)
P QR
S R T
P S P
S A S
What is the minimum number of total variables
required to convert the above into three address
code.
OR
Convert the expression a = b * – c + b * – c into
three address code and also write a Quadruple
representation. (CO3, BT-AN)
(e) With a neat diagram explain the format of the
Symbol Table. And discuss the tree structures
representation of scope information.
(CO4, BT-AP)
[5] TCS–602
OR
Difference between the lexical phase errors and
semantic errors in details with the help of
example. (CO4, BT-AP)
(f) Construct a DAG for the expression :
a+a+a+a+a+a
(CO5, BT-AP)
OR
Explain the role of DAG in optimization with
example. (CO5, BT-AP)
Section—C
(Long Answer Type Questions)
3. Attempt all questions. Each question carries 8 marks.
(a) Consider the following grammar : (CO1, BT-CR)
S aSa / aa
That generates all even length string of a’s except
for the empty string. Construct a recursive-decent
parser with backtracking or this grammar that
tries the alternatives aSa before aa. Show that the
procedure for S succeeds on 2, 4, or 8 a’s, but
fails on 6 a’s. Also give the language does your
parser recognize. (CO1, BT-CR)
P. T. O.
[6] TCS–602
OR
Consider the following grammar and do left
factoring : (CO1, BT-CR)
S a / ab / abc / abcd
Consider the following grammar and eliminate
the left recursion :
SA A Ad / Ae / aB/ ac B bBC / f
(b) Construct the LL(1) parse table for the following
grammar : (CO2, BT-CR)
S aAC / bB
A eD
D bE/E
E eD / dD
Bf /g
Ch/i
OR
What is an LALR(1) grammar ? Consider the
following grammar : (CO2, BT-CR)
S CC C cC C c|d
a. Construct SLR(1) parsing table.
b. Construct LALR(1) parsing table.
[7] TCS–602
(c) Consider the following syntax directed
translation : (CO3, BT-EV)
S ER
R *E {print(*)R/
E F + E {print(+)}/F
F (S)/id {print([Link])}
Here id is a token that represent an integer and id.
value represent the corresponding integer value.
For an input 2*3 + 4 find the output.
OR
Construct SDT to evaluate given arithmetic
expression : (CO3, BT-EV)
Input : a + b * c
Output : a b c * +
TCS–602
P. T. O.