0% found this document useful (0 votes)
38 views9 pages

Compiler Design Old QP - S

The document outlines the structure and content of a Compiler Design examination for B.E. Seventh Semester, including various units covering topics such as syntax analysis, grammar, parsing techniques, semantic rules, and code generation. It includes specific questions requiring students to demonstrate their understanding of compiler phases, construct parse trees, and generate three-address code. The examination emphasizes practical applications of compiler theory, including the construction of parse tables and the analysis of grammars.

Uploaded by

codehacker026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
38 views9 pages

Compiler Design Old QP - S

The document outlines the structure and content of a Compiler Design examination for B.E. Seventh Semester, including various units covering topics such as syntax analysis, grammar, parsing techniques, semantic rules, and code generation. It includes specific questions requiring students to demonstrate their understanding of compiler phases, construct parse trees, and generate three-address code. The examination emphasizes practical applications of compiler theory, including the construction of parse tables and the analysis of grammars.

Uploaded by

codehacker026
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
usy[2[8]4l [TT TT ucs752C B.E. Seventh Semester End Examinations, January 2023 Compiler Design on; 3 Hours Max. Marks: 100 NOTE: Answer any FIVE full questions selecting at least ONE from each unit. s BLL CO PI Questions Y UNIT-1 Explain the role of the syntax analyzer and show the parse tree forthe (06) «L2_ I 14.1 following C statement: A=B+C3 Arte the regular expression to recognize the real numbers considering (06) 32 14d poth decimal and exponent notations. Consider the following grammar G(CFG) s) 13 3 4 EDE+E|E-E|E*E|(E)|id Show that G isanambiguous grammar. y= Y— L— is sy $A Le (os) L201 1Ad Explain briefly the analysis phases ofthe compiler with a neat diagrem- Given the following grammar az) 33 AL ES (bITa LO L,E|E 2 i. Do the changes in the above grammar to make it suitable for LL (I) parser. a i. Compute FIRST and FOLLOW sets. Ss Construct LL (1) parse table.) ¥) UNIT-IL Consider the following CFG (12) L3 3 14. S> BB a ; ~ BS Bid Ss i. Construct the DFA of LR(1) items 4 ii, Construct LR (1) parse table. iii Show the parsing stack and the actions of the LR(1) parser for the input string odd Discuss § attributed and L attributed SDD with examples. Att (os) 12 3) lad UCS}, Marks BLL ¢ Questions ov + eS a js SLR (1) grammar ether the following grammar or not. If (10) 13 b) Write SDD for simple desk given below. Also construct 3 ‘Grammar tT TAFT TE T'syn=T Fodigit __| F.val=digit.lexval UNIT-IIl 5. a) Write the three address code for the following code segment: (io) os b) Using the translation scheme given below, translate the statement (10) 4 [j}*DLi]{j] into three address code .Also construct annotated parse tree for the same. C Assumptions: a“ Ge a andb are 3X4 array of integers S Width of integer :6 Type of a & b: array(3,array(4,integer) afi] & bfi] :array(4,integer) , a{i}[j] & bfiJ[j] : integer Production Semantic rules S—id=E__[fgen(top.getlidlexeme )'=" E.addr) ; } ESE:+E, [{E.addrnewTemp(;gen(E.addr'="E, addr'+* Byaddn); } L—id{E] _ |{L.array=(top.get(id lexeme);L.type= 'ype.elem {L.addr=newTemp();gen(L.addr="E.addr’x’L.type.width);} ESL {E.addr=newTemp();gen(B.addr'="L.array,bas [‘ Laaddr"}):} TLi(E] _ |{L-array= Ly aray;Layp L.addr= new Temp();gen(t gen(Laddr’=" Lyaddr 4°): } E-id {E.addr=top.gel(idlexeme);} lem;t=new Temp(s addr *" Latypeawidth); w UCS752C Questions Marks BLL CO PI mas tree and DAG f and DAG for the expression (10) 3 sio Is 3 x ranslation scl ee e he translation scheme given below, translate the following (10) 4 4 LA sing OO ig three a an into three address, code using ba Sh ‘ode using backpatching method. Also oe aotated pe othe sane wy && (yall) rg ios ised -bp:backpatch , {I :truclist, fM:falsclist and nl:nextlist ‘Semantic rules -igeson___[ Semante les a= | FopMBs {p(B .{1.M inst): B.tl=merge(B AL.B>.tI:B.1= Bp.fl):} - j=merge(By.f1,B2M0); > [fbp(B Al, M.instr);B.=By.AlB. } 1 B.al=B,.f1; B.A=Byal 3) [(BaieB.al: BAB. Al 3} S { ptl-makelist(nextinstr)B.fl=makelist(nextinstr+1): gen(‘iP Ey.addr rel.op Ez-addr ‘goto’ zen(‘goto-') fgen(‘goto-")s} J UNIT-IV qos) 2 4 ck storage allocation strategy ree address code containing (12) ter descriptor and address ry operands after ration Blain briefly the sta Gerate machine code for the following t ferinsiuctions. Also show the regis _depors contents of all the reBiser and memoi Serr ee vach machine instruction by taking into com rextuse information. bic , oad pel Assumptions : i) All operands are to be in register i Thre registers are available ii) Machine instructions are of the form LD reg, mem Stem, reg and ; Pregl rep2,reg3 (result is left in reg! & operation is applied on ree? & +243 contents) sechntvke bi Dict iss ofthe sign of cos SENT an cs) 12 4 NA erate three adress code forthe {0 1g statement and construct (12) ta 4 LA aa ‘graph assuming lower index for oth row and column as 1, ais an #2Y of integers of order 5X0 and width of integers (AUTONOMOUS), BAGALKOTE DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR :2022-2023( SEVENTH SEMESTER) COMPENSATORY Cle Test Semester: vil B code :UCS752¢ Time 4.30 pm.-6.00 pm :12/01/2023 Max. Marks 2 KS.Patil ‘Answer any three full questions Make suitable assumptions wherever necessary Question wer BLL | co} pr UNIT Witha neat diagram explain language processing system os [2 [a (struct recursive descent parser for the following grammar eo) 4 [a ScAdAabla Whats left factoring? How to left factor the grammar? os [ 2 1 {i UNIT-1 Construct canonical LR(O) collection for the grammar given o | 4 | 3 fiat below S->LbL | b Loxtla Construct SDD and dependency graph for the declaration statement | 08 | 4] 3 141 int a b,c,d using grammar given below DSTLT Sint, LSLyid, | Lid UNIT =IIL sing the translation scheme given below, translate the following 10 14.1 pression into three address code using backpatching method. Also nstruct annotated parse tree for the same. PY) &E(( ¥>Z) | | (AB))&&I(B>C) lotations used :bp:backpatch,, tl :truelist, fl:falselist_and_nk:nextlist production | Semantic rules BS8;||MB2 | {bp(B;-fl,M.instr);B.tl=merge(B.tl,B2.tl);B.fl= Bz.fl);} BS8,8&MB> {bp(B,-tl,M.instr);B.tl=B,.tl;B.fl=merge(B,.f1,B2.f1);} B>!B; itl 5) 8518) Btl=B,.tl ; B.fl=B, fl 5} BSE;relE, _ { B.tl=makelist(nextinstr);B.fl=makelist(nextinstr+1); gen( ‘if E;.addr relop E2.addr ‘goto_’);gen(‘goto-’);} MSE (M.instr=nextinstr;} Generate three address code in quadruple form for the following | 05 [441 ‘Statement keb for(i=0;,j-0;i<58& j<5jit+,j++) ali,jj=itj+k Explain the general structure of activation record in brief 05 14d ‘Compute the nextuse and liveness of the following code segment 0S Tai] azb+c b=b+d d=atc c=atb i How to construct flow graph from three address code? Explain in| 05 brief 14.1 BN Sangas 'ASAVESRWAR CNGMELRNG COLLEGE AUTONOMOUS AGATE DEPARTINNY OF contpuTERScHNCt ReNGIECHINe ACADUAN YEAR 2022202 sven SESE) stconociensr Semester : Vit Subject code-Ues7s2c, 023 ‘Max. Marks Subject :COMPILER UESIGH Tle: 1030.12.00 noon Faculty : KS.Path Answer any three fll questions Make suitable assumptions wherever necessary Question Mar gi: | co PL UNIT -i [Using the translation scheme given beiow, translate the statement ‘xali]l}*bliJ[]] into three address code .Also construct annotated | parse tree for the same. | Assumptions: 8b are 3X4 array of integers Width of integer :6 | Type of ‘a &b : array(3,array(4,integer) ‘| ali] & bli] :array(4,integer) ‘| alilfi] & bfij[i) : integer ‘|[ producti | Semantic rules on Si en(top.getlid.lexerne J'=" E.addr);} | E> EE) (E.addr=new Temp(); gen(E.acdr'="E,addr’+ ‘ Eaaddr); ) een L>id[é] {Larray=(top.get(id.lexeme);L.type=Larray.type.elem | | | |Laddr=newTemp();gen(L.addr'="E.addr’'L.type. width); Bol {E.addr=newTemp();gen(€.addr’='Larray.base'{'Laddr') " a COLT) fearray= Li errayjL.cyper :1ype.elen Laddr= new Tempiigentt’ “Eaddr’x'L.type. geni(| adde’=" 11.2 Evid {E.addr=top.get(id. i Construct DAG for the following yao yaar i atas(atata+(atatata)) | xsatatatata Using the translation scheme given below, translate the following | 10 | 4 source code into three address code using short circuit method.Also construct annotated parse tree for the same while((a>b)tl(x>y)&&(y>2)) xextatb a - re rt i ae TT fess rewlabel();B.false=S.next; | | | | Si next=begin;S.code=label(begin)| |B.code | [label( a} jaa) ~~ KEaddr=new E,addr); } | a {81.true=B.true;B; false=newlabell);B,.true=B true; | 82-false=B false;8.code=B,.code| |label(8;,false)| | feaeeel 8:.code;} newlabel();B, false= B false; | 8.code=B;.code| |label(8,.true)| | | | 8.code=E;.code| |E,.code| |ger(? addr relop Ezaddr ‘goto’ B.true) | |gen("goto ‘B.false); } | Build an SDD to convert binary to decimal using the grammar given | 05 4 - | 14.1 | below. Also construct annotated Parse tree for binary 1011 | So. LB Bol | | B50 UNIT-IL | O72) rae eae eat) Generate three address code and partition into basic blocks os | 4 [4 jiat 2 be an SX6 array of integers with lower index for row and column as 1 | a Es | | Ompute the liveness and next use of the variables involved in the 05 | llowing three address code S=btc, c=atd, b=b+e d=atc enerate machine code for the three address code in Q4aAlso show] 10 the register descriptor and address descriptors contents of all the ister and memory operands after execution of each machine |All operands are to be in register lThree registers are available !Machine instructions are of the form. LD reg,mem , ST mem,reg and OP reg1,reg Fegi & operation is applied on reg? & re 2,reg3(result is left in 3 contents) y B.V.V.Sangha’s gases DEPARTM| ACADEMIC YEAR :2022-2023( SEVENTH SEMESTER) WAR, ENGINEERING COLLEGE (AUTONOMOUS), BAGALKOTE. ENT OF COMPUTER SCIENCE & ENGINEERING FIRST CIE TEST Semester BE ivi : ce N ypten DESIGN Division -:B yet 7 752C Time : 10.30 am-12.00 noon pated Us Max. Marks: 45 2 24/14/22 f :kS.Patill fy eS sae answer any three full questions Question Marks | BLL | co | PI UNIT-1 T Treat diagram show how the following statement get 07 23] 1 [141 ‘emleted as it passes through different phases of compilation. Assume a,b and c are real a=b*c+2. Build transition diagramand regular expression that can 08 4 2 1.4.1 ognize unsigned number that may be an integer or real number with optional fraction and exponent 2) Write regular definitions for the following languages 05 4 2 [141 il five letter lowercase English alphabet string that always Begins with‘ or String ends with ‘7 ifit has started with 2 and ends with ‘a’ if it has started with ‘2’ iijall five lette sini ni * ea letter string containing letters a-2 with digits at odd ilijidentifier beginning with alphabet 5 alphabets or digits Phabet followed by zero or | 9) Explain the tools that can be used t : fleece eet fo construct different 05 2 7 aaa a Site the longuages represented by The folowing oe 7 expression llowing regular | 95 ifalb\(aa}bb) oF a eee \ie}byabbtalb)* \iilfaaaye | —| | UNIT -II the following grammars LL(1)? If not state the reason 08 a ->aSa| DSc >ictss'|a seSle Cob Construct recursive descent parser for the following grammar 07 14.1 S>aBa BobCble Ge E Whet is handle pruning? Identify the handles for the 05 a sentence (id+id)*id while reducing to E for the grammar given below ESEST|T [ToTtFlE Fo(E) | id | With examples ,explain the conflicts shift reduce parser may 05 1.4.1 _be subjected to if grammar is not LR(1) | Left factor the following grammar 0s 1.4.1 i) A->aAB|aBelaAcii) ii) S->bSSaaS|bSSaSb|bSb]a

You might also like