Complier Design Jan 2014

Preview:

Citation preview

USN 10cs63

Max. Marks:100

Sixth Semester B.E. Degree Examination, Dec. 20l3lJan.2014

D.,,,:'

tJ.

oooLo

(.)

(.)

ox

d9p,'trca

.:N(B+69!()E:-c o)

o=

;uo()

-6

6 .!l

ioQO-traoj

@=lioa tr=E.<LOz.Yv.uooECOo=o. :itr>Xoo-

U<:' -ooZ

o

Time:3 hrs.

,

c. What are the key problem$'withgrarnmar :

S-+cAd A-+abla.i

3 a. Given the gramrner :

A-+cleB-+dfe

- --:;=)'r:F

i) Compute FIRST and FOLLOW sets

ii) Construct the predictive parsing table

,, iii) Show the moves made by predictive parser on the input ; acdb.Explain with a neat diagram, the model of a table driven predictive parser.

S-+SS+lSS*la.

a. Given the grammar :

S-+CCC-+cCldD Obtain the sets of canonical collection of sets of valid LR(0) itemsii) Design SLR parsing table.

b. Write an algorithm used to compute LR (1) sets of items.c. Write a note on the parser Generator - Yacc.

What is handle pruning? Give a bottom - up parse for the input : vsv * v-t-t and grammar :

top down parse? Write a recursive descent parser for the

(08 Marks)

(10 Marks)(05 Marks)

(05 Marks)

(10 Marks)(06 Marks)(04 Marks)

Gomplier Design

Note: Answer FIVE full questions, selectingutleast Tl,yO questions from each part.

PART _ A

I a. Explain the various phases of complier. Show the translations for an assignment statement.

Position: initial * rate + 60, clearly indicate the output of each phase. , (12 Marks)b. Write thq.regular definition for an unsigned number. Also write the transition diagram.

(06 Marks)

::,,

(02 Marks)

c. What is printed by the following C code?# define a (x + l)

irrtx:2; ',

void b( ) {int x :l; printf("oZd ln", a)'}void c( ){printfl'"%d ln", a); }

void main( ) {b( ) ; c( );}.

2 a. Describe an algorithm used for eliminating the Ieft recursion. Eliminate left recursion from

b. Show that the following grammar,is ambiguous :

E -+ E + E I E * E I (E) | id. Write an equivalent unambiguous grammar for the same.

1 of2For More Question Papers Visit - www.pediawikiblog.com

For More Question Papers Visit - www.pediawikiblog.com

www.pediawikiblog.com

Construct the iarse tree and annotated parse tree for the input string : 1 1001 . (05 Marks)c. Give a SDT for desktop calculator and show its parser stack implementation. (10 Marks)

a. Translate the arithmetiC.expression : a + - (b + c) into dri;rr*r, triples and indirect triples.

b. Give a semantic action i;",,S - if (B) Sr etse sz. [3:ffifiic' Develop SDD to produce directed a cyclic grrpt for an expression. Show the steps forconstructing the directedacyclic graph forthe expression : a-t a* (b-c) + (b-c) * d.

PART _ B

a. Explain the concept of syntax - directed definition.b. The SDD to translate binary integer number into decimal is shown below

Productions Semantic rulesBN-+L BN.val: L. valL-+LrB L. va :2 xLl.val + B. valL+B L.va : B .val

B-+0 B. va :0B-+1 B. va :1

a. Discuss the issues in the design of a code generator.b. Write the tree address code and construct the basic blocks for

segment.sum: 0 ;for(i: 0; i <: 10 ; i ++;

sum: sum +a[i] ;

c. Give the code generation process for operations.

lti.,

a. Describe the general structure of an aCtivation record. Explain the purposethe activation record.

b. A C - code to compute Fiborthcci numbers recursively is shown below :

r0cs63

(05 Mark$,::"",.

',..

"::

.

(08 Marks)

of each field in(08 Marks)

(05 Marks)(05 Marks)

int f(int n)

{intt.s:if(n <: 2) retum I ;

s:f(n-l);t: fln -2) ;

return (s,+ t); '),t, ,

Ifi) Draw the activation tree for the call : (5)it) 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)

(10 Marks)the following program

,F*{<ik*

For More Question Papers Visit - www.pediawikiblog.com

For More Question Papers Visit - www.pediawikiblog.com

www.pediawikiblog.com

Recommended