A 1200csT30205230L
Reg No.:
APJ ABDUL KALhM TECHNOLOGICAL UNIVERSITY
sixth semester B.Tech Degree Supplementary Examination May 2023 (201d
Course Code: CST302
Course Name: COMPILER DESIGN
Max. Marks: 100 Duration: 3 Hours
PART A
Answer all questions, each carries 3 marks. Marks
I construct a regular expression for the language that consists of all strings ending (3)
with 00 over E = {0,1}.
2 Define tokens, lexemes and patterns with suitable exampres for each. (3)
J Given a grammar: (3)
S)(L)l a
L)L,SlS
(i) Is the grammar ambiguous? Justift.
(ii)Build a parse tree for the string (a,((a,a), (a,a))).
4 Compute the FIRST and FOLLOW for the following Grammar. (3)
S)SSIAB
A-)Aala
B)Bbtb
5 Define an operator grammar. Give an example. (3)
t6 What are viable prefixes? (3)
7 Explain quadruples, triples and indirect triples with suitable examples. (3)
'8 what are L-attributed definitions and S-attributed definitions in a svntax directed (3)
translation scheme?
9" construct the syntax tree and then draw thep46 for the statement: '(3)
e :: (a*b) + (c-d) *(a*b)
l0 Explain any three issues in the design of a code generator. (3)
PART B
Answer onefull questionfrom each module, eoch carries 14 marks.
Module I
I I a) Explain in detail the various phases of the compiler with a neat diagram. (9)
Illustrate the output of each phase for the input,
um::a+b*30
where a and b are f'loat variables.
Page lof3
tv
'+
12(X)CST30205230r
b) Apply bootshapping to develop a compiler for a new high level language
N on (5)
machine p. I
OR
12 a) Explain the role of transition diagrams in recognition of tokens. Draw the (g)
transition diagram for the regular definition:
reloP ) < | <: l= l<> l>= l>
b) List and explain any three tools that help a programmer in building a compiler
(6)
efficiently.
Module ll
13 a) Consider the following grammar: (9)
E+E+TlT
T-*T*FlF
F--+-Fl(E)lid
(i) Remove left recursion from the grammar.
(ii) Construct a predictive parsing table.
(iii) Justift the statement.. The grammar is LL (l),,.
b) Design a recursive descent parser for the grammar: s)cAd, A)abl b (5)
OR
14 a) Left factor the following grammar and then obtain LL(l) parsing table. (7)
S)TL;
T)intlftoat
L)L,idlid
Is the grammar LL(l)? Justi$r your answer.
b) Write atl the moves by the LL(l) parser for parsing the input ..int id,id;,,.
[Use (7)
n ,he parsing table created in question number l4.a] .
Moduldltt
15 a) Construct canonical LR(0) collection of items for the grammar
below. (10)
S)L:R
S)R
L+*R
Lrid
R)L
Also identifu a shift reduce conflict in the LR(0) collection constructed
above.
Page 2of3
.v
',.
. 1200csT302052301
b) write an algorithm for computing the closure of an LR(O) items. g)
toR
16 a) construct LALR parse table for the grammar: A-* BB, B--- bB I d (10)
b) what are the different parsing conflicts in the sLR parsing table? (4)
Modute lV
17 a) Write the SDD for a desk calculator and draw the annotated parse tree for the (g)
expression: 4 * 5+ G-(3+2)
b) Explain bottom- up evaluation of s-attributed definitions. (6)
OR
l8 a) Write syntax directed definition to construct syntax tree and three address code (7)
for assi gnment statements.
b) Explain static allocation and heap allocation strategies. (7)
Module V
19 a) With suitable examples explain the following loop optimization techniques: (7)
(i) Code motion (ii) Induction variable elimination and (iii) strength reduction
b) Explain the optimization of basic blocks. (7)
OR
20 a) For the following C statement, write the three-address code and quadruples. (g)
S::A-B+CtD-E+F
Also convert the three-address code into machine code.
r b) Write the Code Generation Algorithm and explain the getregfunction. (6)
*:t**
Page 3of3