For More Question Papers Visit - www.pediawikiblog.com 10cs63
m
USN
Sixth Semester B.E. Degree Examination, Dec. 20l3lJan.2014 Time:3 hrs.
g. co
Gomplier Design
Max. Marks:100
Note: Answer FIVE full questions, selecting utleast Tl,yO questions from each part. ,
o
I a. b.
Explain the various phases of complier. Show the translations for an assignment statement. (12 Marks) Position: initial * rate + 60, clearly indicate the output of each phase. , Write thq.regular definition for an unsigned number. Also write the transition diagram.
lo
L
PART _ A
(.)
ox
What is printed by the following C code? # define a (x + l)
irrtx:2;
w
trca .:N (B+
2 a.
o=
;u
Show that the following grammar,is ambiguous : E -+ E + E I E * E I (E) | id. Write an equivalent unambiguous grammar for the same.
c.
What are the key problem$'with top down parse? Write a recursive descent parser for the grarnmar : - --:;= )'r:F (08 Marks) S-+cAd A-+abla.
oj
3 a.
i
Given the gramrner
:
A-+cle B-+dfe
w
tra
w
-6
6 io QO-
Describe an algorithm used for eliminating the Ieft recursion. Eliminate left recursion from
b.
o()
.!l
(02 Marks)
.p ed ia
()E:o)
-c
::,,
void b( ) {int x :l; printf("oZd ln", a)'} void c( ){printfl'"%d ln", a); } void main( ) {b( ) ; c( );}.
d9
p,'
69!
',
(06 Marks)
ik
c.
(.)
ib
o o o
@= lio a tr= E.< LO
w
i) ii)
z.Y v. uoo
ECO
o= o. :i tr> Xo o-
U< :' -
D.
,,,:' tJ.
Compute FIRST and FOLLOW sets Construct the predictive parsing table (10 Marks) ,, iii) Show the moves made by predictive parser on the input ; acdb. (05 Marks) Explain with a neat diagram, the model of a table driven predictive parser. * What is handle pruning? Give a bottom - up parse for the input : vsv v-t-t and grammar : (05 Marks) S-+SS+lSS*la.
a.
Given the grammar
o
S-+CC
Z
C-+cCld
o
:
D
o
b. c.
Obtain the sets of canonical collection of sets of valid LR(0) items ii) Design SLR parsing table. Write an algorithm used to compute LR (1) sets of items. Write a note on the parser Generator - Yacc.
For More Question Papers Visit - www.pediawikiblog.com 1 of2
(10 Marks) (06 Marks) (04 Marks)
For More Question Papers Visit - www.pediawikiblog.com
PART _ B
g. co
Explain the concept of syntax - directed definition. The SDD to translate binary integer number into decimal is shown below Productions
BN-+L
(05 Mark$, ::"",.
',..
":: .
Semantic rules
L-+LrB
L+B
BN.val: L. val L. va :2 xLl.val + B. val L.va : B .val
B-+0 B-+1
B. va B. va
lo
a. b.
m
r0cs63
:0
ib
:1
a.
Translate the arithmetiC.expression : a + - (b + c) into
b.
Give a semantic action i;",,S if (B) Sr etse Develop SDD to produce directed a cyclic grrpt for an expression. Show the steps for constructing the directedacyclic graph forthe expression : a-t a* (b-c) + (b-c) * d.
w -
dri;rr*r,
triples and indirect triples.
sz.
[3:ffifii
.p ed ia
c'
ik
c.
Construct the iarse tree and annotated parse tree for the input string : 1 1001 . (05 Marks) Give a SDT for desktop calculator and show its parser stack implementation. (10 Marks)
(08 Marks)
lti.,
a. b.
Describe the general structure of an aCtivation record. Explain the purpose of each field in the activation record. (08 Marks) A C - code to compute Fiborthcci numbers recursively is shown below :
int f(int n)
{intt.s:
<: 2) retum I s:f(n-l); t: fln -2) ; return (s,+ t);
;
w
w
w
if(n
'),t, ,
I
f
i)
Draw the activation tree for the call : (5) W'hat is the largest number of activation records that ever appear together on the stack? ,,,,:, (06Marks) c, ' Explain the performance metrics to be considered while designing a garbage .oll..jg]._ _.. ' (06 Marks)
it)
a. b.
Discuss the issues in the design of a code generator.
(10 Marks)
Write the tree address code and construct the basic blocks for the following program segment.
sum: 0 ;
for(i:
c.
<:
0; i 10 ; i ++; +a[i] sum: sum ; Give the code generation process for operations.
,F*{
For More Question Papers Visit - www.pediawikiblog.com
(05 Marks) (05 Marks)