0% found this document useful (0 votes)
5 views

Compiler design pyqs

The document is an examination paper for a B.Tech Compiler Design course, covering various topics such as grammar, parsing, code generation, and optimization techniques. It includes multiple-choice questions, coding tasks, and theoretical questions related to compiler design principles. The exam is structured into parts, with specific instructions for answering and submitting responses.

Uploaded by

sj3035
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)
5 views

Compiler design pyqs

The document is an examination paper for a B.Tech Compiler Design course, covering various topics such as grammar, parsing, code generation, and optimization techniques. It includes multiple-choice questions, coding tasks, and theoretical questions related to compiler design principles. The exam is structured into parts, with specific instructions for answering and submitting responses.

Uploaded by

sj3035
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/ 20
STe| aR Tyalbje SeS\e R>bRe|X|Y X>AB|b Yo%le Aodale 28a. Use the following grammar and check whether the word id, fd is accepted 3? or not? E> EADIE TTF |F Fo@\id (oR) '. Construct the operator precedence parsing table for the following grammar 3 3 and check whether the input sting id fd = id is successfully parsed or not. so SOR Loe Loud ROL 29, a. Create the code in target language forthe following statements wos 4 @i=a-b Giu=a-c (ii)verte (and (Wd (OR) . Generate the three address code for the statement a+b+e-+4 os (quadruple (i) triple (i) indirect triple (iv) syntax wee 30... Build DAG forthe following code segment. aa ii, Eliminate the redundancy inthe following cade sas ‘int add_ten (int x) ) (or) ', Elaborate the concept of dataflow analysis. Analyze about when gen i and where kill i used. Deseribe with suitable example. eg. No. || B.Tech, DEGREE EXAMINATION, NOVEMBER 2022 Sixth Semester 18CSC3041 - COMPILER DESIGN (or the candidate adit rom the academic year 2018-2019 10 2019-2020) Note: ‘9 Part- shouldbe answered in OMR sheet within first 40 minutes and OME sheet shouldbe handed over toil invailator at the end of" minute (i) Part-B should be answered in answer book Time: 24 Hours Max, Marks: 75 PART —A (25 x1 = 25 Marks) arene “Answer ALL Questions 1. Inthe compiter, the funetion of intermediate code generation is doneby = 11? (A) Lexical analysis, (B) Syntax analysis (©) IMcode generation (D) Code generation 2. Which tools used for grouping of characters in tokens in the compiler? = 122 (A) Parser (B) Code optimizer (©) Code generator (D) Seanner 3. Whats tinker? vee ieeei (A) tis always used before program (B) It is used to create load module execution (©) It links the binary brary files (D) Itis connected with parser with code 4. Keywords are recognized inthe compiler during iene (A) The code generation (B) The data low analysis (C) ‘The lexical analysis of the (D) The program parsing program 5. Maximum number of states of DFA converted from an NFA with mstates 1? 2 2 a @) or (0) 20 6. Identify the (1) grammar eaeae (A) SFiBES SE (B) 4->Blc,B->ab,C ad (©) A>BleB-rablAd|e, — (D) A> B|eBrablecrd cod 7. Which one of the following is nt an eror-recovery strategy? ee (A) Panic mode (B) Phrase level recovery (©) Error production (D) Phrase recognition 8, YAACis a computer program for__eperating system, as (A) Windows ®) Des ree ae Leo eens soassesemas "1 12, 13. 14 16. v. 18. The variable which produces ¢ is called as (A) Empty variable (B) Nallable variable (©) Terminal (D) Non terminal ‘The process of restating the deviation of a production using dlferent derivative of same non-terminal duc to unmatched input string is known as (A). Bottom-up parsing (8) Derivation (© Backiracking (D) Top-down parsing Which of the folowing parser i a top-down parser? (A) LALR @) LR (C) Operator precedence (D) Recursive descent ‘An LR parser can detect a syntactic error as soon as (A) The parsing tars (B) During left to right sean of input (©) During right to left scan of input (D) Parsing ends fa state does not know whether it will make a shift operation or reduction fora terminal is called (A) Shifvreduce conflict (C) Shift conflict (B) Reduce'shift confict (D) Reduce conifict, ‘When B is empty (4 P.a) the reduction of A >a is done by. (A) Ifnext symbol is terminal —(B)_ Only if the next input symbol is (©) Onlyiifthe next symbol is A (D) Only ithe next input symbol is The construction of the canonical sets and LR is done by (A) Combining LALR items with (B) Combining LR(O) items same lookahead (©) Combining LR() items with (D) Combining LR(O) items with same ending romeending, Code generator uses function to determine the states of available registers and the locaton of name values, (A) seteg (©) piReg (B) cinkeg (D) gots Which of the following is nota form of intermediate representation? (A). Abstract syntax tree (B) 3-address code (©) Dac (D) Reverse polish notation How many descriptions are used to track the registers while gener code ing the 2 3 4 © 5 In directed acyclic graph, leaf nodes not represent? (A) Identifiers (B) Names (©) Constants (D) Expressions 20, a 2, 24, 25, 26. 2a, b Convert the following expression 23-44 into postfix. The answer is ‘ (@) B4e= (B) 2384+ (©) 12344 (D) 04234 Which compiler runs on one machine and generates code for multiple machines? (A) Multipass compiler (©) Optimizing compiler (B) Cross compiler (D) One pass compiler ‘A fiagment of code that resides in the loop and computes the same value! ‘each iteration is? (A) Induction analysis (©) Loop-invariant code (B)_ Strength reduction (D) Code analysis Substitution of values for names whose values are constant, s done is 1 (A) Local optimization (B) Loop optimization (©) Global optimization (D) Constant folding AA variable is called an ‘by-aloop invariant vahis (A) lnvatiant (©) Strength variable is its value is altered within the loop * (B) Induction () Loop ‘Dead code plays no role in any program operation and therefore 1 (A) Iteanbe eliminated (B) Itnced not be eliminated (©) Ircan be replaced (D) Itean be rearranged PART ~ B (5 x 10 = 50 Marks) Sean tee [oy cls eG pe eecosnuiete a (ab+aay’ ba, BO ope ee moves Note: Reg. No B.Tech, DEGREE EXAMINATION, JUNE 2023 Fifth Semester 18CSC362] - COMPILER DESIGN (For the eandidates adonied during the ucedemic year 2018-2019 to 2021-2022) i. Part-A shouldbe answered ia OMR sheet within first 40 minutes and OMR shes should be handed over to hall ivigilator at fhe ead of 40 minus. fi Part- Bland Part- C should be anivered in answer booklet. ‘Time: 3 Hours _ seven “The regula exresion (1)*() represents a language with ‘ (A) Nonempty binary strings (8) Empty and nonempty binary strings (©) Odd noneepy stings (@) Even nonempty stings “The total amber of sates to build the given language using DFA: L={ww has cexaclly 2s dat east? b's} wie @n On OB Which ofthe flowing snot a regular expression? (A) [Hb (B) (O41) 0bea1)*(arby)? (Orst+I0" Dawa ‘Regular expression ©” is equivalent to we Bo coo Or! For the grammar rules given below what isthe FIRST(S) $ Aa[bB, Ace ware ®): abe Dyabce Grammar of te programming i checked at which phase of compiler? (AY Lexical amlysis (@) Syatax analysis, (©) Semantic naysis (@) Syn dirwcted translation Whi ofthe allowing regular expression opertor hrs highest precedence (A) Concatension (B)Union (©) Positive chsure (D) Kleene closure In which paning, the parser constructs the pase tree from the start symbol and ssansorms eat the input symbol (A) Bottom-Us Parser (By Top-Down Parser (C)Botha sb (D)LR PARSER The grammar A 2 AX (A) |¢ is not suitable for predictive-parsi srammat is? bosouse the (A) Left factoring (B) Le reousive (©) Rightrecusive (©) An operator grammar For the gramnar, F.C EE |(F)|¢, numberof pase trees to produce empty sting is? (A) One (B)Two (Thee @yInfnite 2100 1 13 14 V. 18. 19. 20, 2. 2. Which grammar rls violate the requiemens ofan pert gamma PES piSeer Sey aie (8) Tony @) 1 and3 only (© tnd Sony (©), Sand 4 only ‘Afi of recursive dosent parsing tht doesnot rea ny backtracking it known (A) recusive parsing (© predictive parsing (B)non-seousive parsing () non-preditive parsing ‘Which statement is an abstract form of intermediate cade? (A) Baddress| (@B)2aadaress (address (©) Intermediate code In parse tree leat nodes are called? (A) terminals (@)2oo-teminals (C)sub-teminale (Dy halé-erminals The interior node of syntax tree is (A) Operators @) Keywords (Opboth ad Dyeonst Alatch is constructed using which two cross coupled? (A) AND OR gates (B) AND gates (C)NAND and NOR gates (D)NAND gates ‘Which sno par of aatime mesnory subdivision? (ay Stack @)Heap (©)Satic data () Access lnk In which stomge allocation strategy size i requied at compiler time? (A) Static allocation (B) Dynamic allocation (©) Stack allosstion (D) stack static allocation is tol tha depicts the struct of basic blocks, lps to see the low ‘values owing among the basic blocks, and offers optimization capaa ‘®)cac (Osac @pPac “The pb at shows basic blocks an heir sucssorelaionship is alld (aya (@) Flow soph {© contol aap (©)Hamlonion geoph Part B (5 4 Marks=20 Marks) ‘Answer any § Questions ‘The two tests schemes canbe reduced to one in input busing technique? justify ote ansever with an gor Raju is authoring a book on compiler. He makes sure that the Sst page isan index alowed vo skanvicdgnen pees. Design a DEA forte angie El Elis over fat ‘Nove: index page and acknowledgment pages are refered to strings “a', “b! respectively. 25, n 28 2. 20 3h 2 reas 3. Elimizate et recursion and lef factoring inthe following grammar: X=Yalbie Y>¥el¥dla Z>aZX| Re) aze heck the fellowing grammar is ambiguous or not by parsing the input sting aa" ‘Write an inherited aftbute semantic rule foe following production and draw syntax twee for double abe aa o p= Taint To float To double LOL iid Find LEADINGQ and TRAILING for ll he non terminals in the following ASA-BIB BSaicip C2esDID DOCAIRIy Diseuss the various peephole optimization techniques in detail Part-€ (8 12 Marks = 60 Marks) ‘Answer All Questions 8) Consider the input e~asb*5. With a neat sketch, ilstrate how the input is ‘eansformed into assombly code, using al the phases of compiler (O1 « by Describe the structure of LEX program with example ) Find the canonical collection of LR(0) items forthe following gratnnar: pai om © Fore ren gama See ES ETTRAGL row 0 aoe ee ae Doplale Check whether the following inp ar scoped or nt by the gamma using fecusive dosnt parsing Doan ss (or) 1) For the given grammar S-» 0S1 | 01, Writes derivation and draw parse tee for the sting w= 0515, # esrb te aeottng cia fx foo conta seme ') Describe the various methods of implementing th threo address ststements with anexample 2) Describe in detail about epimizato of basic Blacks wilh exsmple (OR) + lustre in detail about the code generation algoritim with an example Ne (For the candidates admitted during the academic year 70 i. Part-A should fll aviiltor a he end of 40 mites. fi, Part= Band Part C shold be answered in answer booklet. Time: [Reg No B.Tech, DEGREE EXAMINATION, MAY 2023 Sinth Semester 18EEE336T - COMPILER DESIGN 2019 to 2021-2022) answered in OMR sheet within fist 40 minutes and OMR sheet should be handed ove to Hours ‘Max. Marks: 100 Part -A 20% 1 Marks= 20 Marks) Mate BL co ‘Answer AM Questions ‘Whats compiler? ape (A) system program that converts (B) system program tht conver instructs to machine language ‘machine language to high-level language (©) system program that writes (D) None ofthe mentioned instructions to perform In which ofthe following phase ofthe compilers Lexical Analyser? eh (A) Second By Taied COFies (D) Fourth Keywords are recognized ina compiler during Hoon (A) The code senestion (8) The dataflow analysis (€) The lexical analysis (D) The program posing Consider th production ofthe grammar S>AAA->aa A>bb Describe the language 11 2 spose by the production grammar. (A)L= joaso.aab ba bbbb) (B)L= {ababboa,aaab, bass) (C)L= faaat bababaa bbbb} (D) L~ {saan abab bbaa2aab} DFAisan abbreviation of a (A) Non Deteninistic Finite set (@) Deterministic Finite Automata ‘Automata (©)Non Deterministic Finite Automata (D) Deterministic Finite set Automata Parsing is ca1czorized ito how many types? rae (4) Three ype (8) Four types ()Tworypes (D) Five ypes Which of the following derivations does a top-down parser ue while parsing an 1 1 2 input cine” (A) Letimost desivation (@) Lemos derivation in reverse (C)Rightmos derivation (D) Righimost derivation in reverse Which phase ofthe compiler i also known as Parser? mateo (A) Code Optinization () Semantic Analysis (©) Syntax Analysis (D) Lexical Analysis Find the grammar gives multiple parse tres foe the same sting vas (A) Unambigioas (B) Regular (C)Ambiguous (D) Syntsetic Grammar n 0. 18, 20. 21 2 2. 24, 2s, Which of the following grammar rules violate the requirements of an operator rammar? GV) SOR (a) ony (8) () and Gi) onty (©) Gi) and Gp only (D) Gp and Gv) only bottom-up parser generates (A) Left-nost derivation in reverse (B) Lef-most derivation (©) Rightamost derivation in reverse (D) Right -most derivation ‘Which phenomenon happens wien the noo-terminal on the left side is repeated as the fist symbol onthe ight sie? (A) Left most derivation | (C) Let factoring The bottom-ap parsing method is aso called (8) Shift reduce parsing (Ch Recursive descent parsing (B) Left recesion (©) Left parsing (@) Predictive parsing (D)SLR Parsing Which ofthe following parser is top-down parser? (A) ABLALR parser (B)ALR parser (©) Operator precedence parser (Dy Recursive descent parser ‘Choose the component important for semantic analysis. (a) Yaee B)Lex (©) Symbol Table (D) Type Checking In which ofthe following tre, the lef incates the operand, and the interior node represent he operator. (A) Symtaxtee (By Parser wee (© Structured tee (D) Sematc tree \Which mapping is desoibed by the implementation ofthe syntax diectd translator? (a) Pase table 8) Ioput (C) Oupat (©) loput-Ousput Choose the structure has four feds (A) Parse tree (8) Triples (C) Tie Tiles (©) Quadruples ‘Which of the following is used in various tages o phases ofthe compiler? (A) Records (®) Program (©) Symbol Table (©) Table Determine the statements an abstract form of intermediate code (A) Saddress (8) 2- address (Chadéress {(D) termediate code Part B (Sx 4 Marks= 20 Marks) ‘Answer any $ Questions Differentiate between compiler and interpsté. Define the following terms: 2) Lexeme b) Token, ‘With examples discuss about eft recursion nd let fctring. Define let most derivation and right most derivation with examples. ‘Whats aDAG? Menton its applications. Martet. co) 28. 28. 30 3h 2. eee 44 Demonstrate the process of compilation. Ilustrate the ouput of each phase of onan forth input =e) re) 2. (oR) >, Forthe fellowing expression find the minimized DEA: a°b/'a, Remove the Left Factoring inthe following: A> AB. aBo/ aA. liminate (Consider the following grammar and eft ecursion- Sie LoLsys (08), '. Discus in detail sbout Predictive parser with an example. Construct Operator precedence relation table for the following grammer: Bape T/T Tare FE Fa@/id ‘ad pase he input string id + id (on) ’, Neatly Explain the SLR parser with an exarple, ‘4 What are the various methods of implementing 3-sdéresstatements? Explain with cxamples? con, + Listand explain the atebutes of Synitx Directed Translation Scheme, «4 Narrate th characteristic of Poephole Optimization. (OR) '. Enumerate Basi Blocks and Flow Graphs, Note: re as B.Tech DEGREE EXAMINATION, NOVEMBER 2023 Fifth Semester 18CSC3621 - COMPILER DESIGN (or the candidates admitted daring the academic year 2020 - 2021 & 2021 - 2022) i: Part- A should be answered in OMR shoot within frst 40 minutes and OMR sheet shouldbe handed over to hall iavigiltr atthe end of 40® minute ii Part= Band Part ~C should be answered in answer booklet ‘Time: 3 Hours Max. Marks: 100 PART-A@0%1=20Marks) Mariel, CO ‘Answer all Questions Keywords ofa langoage are recognized during ina compile. (A) parsing ofthe program | (Bp leneaT analysis ofthe program (©) code generation {(D) dataflow analysis vtputoflesial sear is_ (A) machine code (B)imermediate code (C)a list of tokens (Dya parse tee Major Pats of compiler are in number wz @9 oe oe CCharecters are grouped into tokens in which ofthe following phase ofthe compiler 1 ‘sign? (A) Code generator (B) Lexical analyzer (© Passer (©) Code optimization Jn which parsing, the parser constructs the parse tee ftom the start symbol and transforms it ino the fp symbol (9) Bottom-Up Parser {B) Top-Down Parser (O)Botha&b (D) LR parser What isthe expansion of CEG? (a) Compiler (B)A language expression (C) Regular Expression (D) Context Free Grammer ‘A context free laguage is called ambiguous if —— (A) Tebas 2 oF more than 2 left (B)Ithas 2 or more than 2rigbt erivations for some terminal string derivations for some terminal string wel) wel @) (©)thas 2 cr more than 2 fet and wight (D) Ithas 2 or more than 2 lef ervatons for someterminal sing derivations weL@ (Gramma that canbe translated to DFA's is (A) Lef lines grammar (@ Right lines grammar (©) Generic grammar (©) linear grammar ‘A bostom up parser generates (A) Right mott derivation (B) Rightnos derivation in reverse (©) Lefimostdervetion (D) Lefimort derivation in reverse 10. 4, 2. B 14 18, 18. 24 2, Shift Reduce parsers are (A) Top down Parser (B) Bottom Up perser (©) May be top down or botom up (D)LR Parser Which ofthese is also known as look-head LR parser? (a sik @LR (ouR () Top down Parser ‘Whats th similarity between LR, LALR and SLR? (A) Use same algoriti, but different (B) Same parsing abe, but different parsing table ‘algorithm (©) Their Parsing tables end algorithm (D) Bota Parsing tables and algorithm se similar but uses top down, sxe diferent, spproach, 'A grammar that produces more than one parse tee for some sentence is called @) Ambigwons (B) Usambiguous (©) Regolae (D) Both aand Which of the following stv for machine language? (A) Continuous execution of program (B) Depicting Now of dats i a system segments (OA sequence of instructions which __(D) The language which interacts with solves a problem the computer using only the binary digits 1 and 0 ‘The average time required to reach a storage location in memory and btsin its cotati called the oe (A) Sesk ime (B) Tumaround time (©) Access time (D) Teassertine ‘Which loader function is accomplished by londer? (a) Reallocation (B) Allocation (©) Linking () Leading Which ofthe following are storage allocation statgies (A) Static allocation {) Sickallocetion (©) Heap allocation (D) Both aand DAGiis an abbreviation of? (A) Detecting Acyelic Graph (B) Data Acyclic Graph (©)Dynamic Acyclic Graph (D) Directed Acyelic Graph ‘The graph that shows basic blocks snd their successor relationship is called @pae (B)Flow graph (©) contro aap (©) Hamiltonion graph ‘Which snot part of runtime memory subdivision? (Suck By Heap (C) State data () Access link PART -B ($ x 4= 20 Marks) ‘Answer any § Questions Design s Deterministic Finite Automata (DFA) to sccept strings baving 101 a: a substing over Z=(0.1}. Write the fomaal definition of the ‘DFA and drew the ‘tanstion table. Abo show that the string T1O100 i accepted by the DEA. Analyze and elaborate onthe various stages ofthe compiler with neat diagram tora 12a faa ques 2B. 2%. 28. 26. 27. 28 2. 31 22 Find the Leftmost and Rightmost derivation and draw irc forgiven expression era eta ESETE[ETEV@)/a |b © enidsid ia Give the rule for Fist and Follow and forthe given grammar identify aa eae a TE 0 ii Follow 9 Construct the precedence table for the following grammar Determine the Lead and # 23 Trl BOEAE hoe Enfule the epeions for he SDD mmwuted parse oe for the flow #14 expressions. 3°34, List snd elucidate ny tree issues in the design of a code generator. A ears PART-€ (6% 12=60 Marks) Marie BL 0 ‘Answer all Questions (4 With « nest diggram, deseribe the Compiler consruction tools and Input 122 2 fering (oR) () Explain in detail with a neat diagram i) "Analysis Phase i) Syatbess Phase (@) Construct a Predictive LL(1) parser and match the input idtid*idismatching 1232 ‘wth the given grammar. ESTE ESE TF Torrie Fo id (oR) ( Conary suck plementation of if reaping forthe grammar (1) 8 ToUsia ‘Show wheter the following tring willbe accepted or not. (a, ((, a, (8,8) (@) Explain in detil about DAG for basic blocks with example. noao4 cor) (6) Display the parse tree in top-down tanslation scheme for following input string eal, id 2, 3. (@) Construct Stack Implementation of Shift Reduce parsing forthe grammar 1243 EEE ESEE ES) [Eid od the int string i dD", (OR) (6) Explain the low of contol statements for Boolean expression (@) Discuss the various peephole optimization techniques in detail eu acsss (oR) (8) Elaborate the festures and algorithm for DAG and construct the dag. forthe following basic block: dabee enath Babee ered B.Tech. DEGREE EXAMINATION, JANUARY 2024 Sixth Semester 18CSC304) - COMPILER DESIGN (Porth candidates dite from the academic year 2020-2021 & 2021-2022) Note: {Pare should be answered in OMR shes within fit 40 minus and OMR sheet should be handed over {otal invigistor ah en of 0 mine (i) Part= Ba Part-Cshoald be answered in answer booklet, Time: 3 hours ‘Max. Maks: 100 PART ~ A Q0x1 =20 Marks) nem m0 ro “Answer ALL Question, 1. Ina compiler, keywords of language ae recognized during i (A). Parsing ofthe program (@) The cade generation (© The lexical "analysis of the (D) Dataflow analysis program 2, The cuput of esc analyzer is rane (A) A parse tee (8) Imemedinte code (©) Machine code (D) Asiteam of tokens 31. The numberof token inthe following C statements i se printf ("1% = 963", ws (8) 26 © 10 ©) 21 4, The lexical analysis fora modem computer language such as java peed the power 1021 2 ‘hich one ofthe following machine models na necessary and slice sense? (a). Deterministic pushdown automata (B) Non deterministic pushdown automata (©) Finite state automata (0) Turing machine 5. Which ofthe following derivations does a top-down parser use while paring an |? 23 input sing? The inp is assumed 10 Be seaned in leo right onder? (A) Lett most dervation (B) Left most derivation waced out in (©) Righmos derivation () Right most derivation raced out in 6 A.CFG is not closed under actinay 3 (A) eration (8) Concstenation (©) Dotoperation (©) Union operation 7 Parsing also known as ee (A) Lexical analysis (©) Sym analysis (© Sematic analysis {) Code genertion 8. Consider the grammar with non-eminals N= {S,C, Cs, terminals ds 3 T= fab, tse] with S” asthe stat symbol and te following set of rules SictS9,|a; 5, res cb “The grammar isnot (1) because: (A) Htis eft recursive (B) is ight recursive (©) is ambiguous (©) Wisnoccontext fee 9, Which ofthe following isnot an operator grammar? raga ) Boce @) BACAtDIe (©) BoD (©) BODaDeD 10. Consider the following grammar: A» Ba|d;b-> Bx\a whatis LEADING 123 A) fal ® fda © twa () Cant be determined 11, What isthe lokhead symbol of the give production C> ad.A, f° To @) (a Bt Oa O& 12. Which ofthe following statements ae fale? baa (A) LL() isa top down parser B) LLG) is op down while LRG) is bottom up parser (©) LR(Wist0p down perce () LRG) is botiom up parser 2B. isa tool that depicts the structure of basic Blocks, helps to see the low of ||? & ‘alues flowing among basic blocks (a) DAG. @) CAG (©) SAG (D) PAG 14, In algebmic expression simplification, a= a+! can simply be replaced by 12 4 wa @) INCa (©) DECa ©) MULa 15, Which ofthe following isnot for of intermediate representation? toad (A) Absiract synize tee (8) 3-adaress code (©) Directed cyelic eraph (©) Reverse polish notation 16, Code generator uses _:___ function to determine the status of available registers. 11 and the location of name values. (A) seiReg (B) cinkes (©) pies (D) getReg 17, Which ofthe following isnot a loop optimization technique? tas (A) Elimination “of common (8) Code motion subexpression (©) Reduction of strength (D) Flimination of induction variable 18, How many points are present inthe code segment? nas 4 a3 @ 1 © 4 ©) 5 19, Wht form of optimization can be applied on:al+3]= Cli 3}*dUi+3) ere (A) Elimination ef common (B) Elimination of dead variable subexpression (©) Nooptimization is possible (D)_ Elimination of induction variable peter casnssscscone 20, Which of the optimization is not possible in the given code? 1232 x=3 (A) Constant folding (B) Copy propagation (©) Renaming variables (©) Bliminaion of common sub 21. Discuss in detail on compiler construction tools. eaaa 22. Constructa deterministic finite automata that accepts numbers hat are divisible by © 3) 9 five 23. Compute FIRST for the following grammar aoa ag ‘S-> ABCD Arak B>cD\b Cocke D> 4a\d|e 2A Pare teint sing “ities” wing si rece pang forthe folowing © 7 > > Fens IES a Bob 25, Discus he les involved in const the SLX psn ble eae 5 “26, id he sian nd DAG frie folowing exreson sae (xb ye(e~d) 8) 27. Ue i atin oa mi iw de sea ‘ for j= 0;j- ABCD Arak B>CDIb Cocke D> Aaldle Consider the following grammar SoMa LLS|S Construct lft most derivation and parse tee for (a,(a,a)), (ory ‘Show the following grammar is LL(1) and parse the input string "baba". SoMa L>LS|S ‘Construct an operator precedence parsing table forthe following grammar. SI AtBeC A+Ded\a BoBAAlb C4D+Ale Dod Is there any confit (oR) Perform canonical LR parsing forthe following grammar. SLARIR Lv eRid Ro “Express the sematic rule for productions of Boolean expression write three adress ender FE <1008> 2008 Bst= 9) ‘State the diferent ways of representing intermediate languages. (oR) Explain the wansltion scheme to produce three address code for assignment satements, Write tree address code for the following expression (wes) + (+2) (eres y +2) ‘Explain in detail about displays. Also explain how variable length data is handled by compilers. (or) Discuss in detail about storage allocation strategies witha block diagram. ieee sale: B.Tech, DEGREE EXAMINATION, DECEMBER 2023 ‘Sixth Semester 18CSC304) — COMPILER DESIGN (or the candidates admitted from the academic year 2020-2021 & 2021-2022) Note: {Part A should be answered in OMR sheet within fst 40 minutes and OMR shes shouldbe handed ‘overt al vigils atthe end of 40" minute. (Gi) —_Part-IB& Part~C shouldbe answered in answer bookie. hours ‘Max. Marks: 100 PART—A 20x 1=20 Marks) ee ‘Answer ALL Questi 1, The FSA to recognize the words “infrared” and “infastructure” has teas numberof states, (a) 20 @) 2 © 15 © 17 2. The equivalent of Rj =(rs-+7)"r is tee (A) rer ery ®) Fortnt (©) rrr} ©) erent 53. The numberof tokens in the following C code segment is Haas switch (0) i case I:b= eter ds break; efault } (a) 26 27 (©) 28 (©) 20 4. TELL is represented by (a/b/c)"de and L2 is represented by (1/2/3)"34 | > 1? then choose the right string for L1. L2 (a) e234 (B) abccede112334 (©) abeoce 1232 (D) e224 5, Which of the following derivations does a top-down parser use while parsing an input string? The input is assumed to be scanned in Tet to right order? (A) Left most derivation (B) Left most derivation traced out in (©) Right most derivation (D) Right most derivation traced out 6. Consider the grammar Tea xy 20d 20 yoe joe Identity the frst (y) @) (8) ®) fee © foe o & 7. Consider the grammar shown below, oe S$ LENSS'|a Starest> Eb In the predictive parsing table, M of this grammar, the entries M[S!,e] and AM{S",S] respectively are, (A) {S-res,S'e} and {Sve} (B) {S++ es} and {8! e) (©) (Ses) and} (D) {S> eh and (8! +6} 8. Consider the grammar with non-terminals N= {S, C, Ci}, terminals ¢ 2 2 ‘T (a,b, i,t¢) with ‘S" as the stat symbol andthe foliowing set of rules: Sr letS5;\a; S;resle; orb ‘The grammar is not LL(1) because: (A) Icis let recursive (B) Itis right recursive (C) Itisambiguous (D) Itisnot context free 9. Consider the grammar E—>E+n|Exm|n for a sentence n+nxn, the Inandes in the right sentential form ofthe reduction are (A) nE+nand E+nxn (B) nB+nand E+Exn © nntnandntnxn (D) Exnand B+nxn 10, Consider the augmented grammar given ae sos Solid LLS|S ‘How many LR(O) items can be formed wT @ 9 6 ©) 5 11, Which of the following grammar rules violate the requirements of an 1 > 3 operator grammar @ ABC @ A>BrC Gi) Ase Gv) AS Ba Cr (A) () and Gv) only (B) ii) and Gv) only © (and i only ©) (and Gi) only aed apasinesca0e 14, 15, 17 18 Consider the augmented grammar given slos Said LL s|s Let I, closure {81S}. The numberof tems in the set Goto (li is ws B 4 ©3 1 ‘When code is generated for “a 4”, the locations let for back patching ae, (A) Falselistofa b, false list of > dinuelist ofe> d > b, tre lst of © d, false list ofe>d Consider the wansaton scheme shown below ‘Some ROT Print o;}Rie 7 > num (Print (oum.va) Here numa is a token that represents an integer and num.val represents corresponding integer value, For an UP suing “9*5+2" this transaction scheme will rat (a) 92542 @) 9542+ © 9824+ (D) +982 (On ‘translating the expression given below into quadruple representation, hhow many operations are required? (I+ j)-+(e+ f)*(+m+n) ws @ 6 ©7 3 Cross complies isa compiler (A) Which is writen in a different (B) That generates object code for language from the source themachine is running on language (C) Which is written in the same (D) That runs on one machine but language as the source produces object code for another language ‘machine Which of the following optimization is not carried out with DAG represeatation ofa basic block? (A) Elimination of common sub (B) Dead code elimination expressions (C) Elimination of redundant loads (D) Constant folding and stores ‘The statement followed by a conditional jump is @ (A) Leader B) Entry (©) Exit (D) Next use information assesses 19. ‘The following code isan example of fas void add ten (int x) return x= 10; printf value of x is %d”, x); } (A) Redundant instruction (B) Unreachable code climination (©) Flow of contol optimization (D) Reachable code 20. The sequence of procedure calls of a program corresponds to which 1 1 5 ‘waversal of the activation tree, (A) Invorder traversal (B) Pre-order traversal (©) Post-order traversal (D) Levelorder traversal PART—B (Sx 4=20 Marks) uns me 0 ‘Answer ANY FIVE Questions 21. Construct DFA for the language over alphabet a, b, where string will not ¢ 2 * Ihave ‘aba’ as substring, 22. Show thatthe following grammar is ambiguous: ee S$ iCis|1C1SeS |a Lb 23, Compute FIRST for the following grammar cease ‘S> ABCD Aral B>CD|b C3Cle D> Aaldle 24, Parse the input string “ibtibraea” using shift reduce parsing for the following 4 2 3 gamma. i 15 a Bob 25. Lis the properties of LR parser, mention the types of LR pase sas 26. Tanalate the given expression int tps and indirect ples sae (ard elerd) Hand! <)=b400 27 Lis the possible transformations that are availabe the below code. forGedien iy) + form 033m) 962) Gejrsea; (T+); PART —C (Sx 12 = 60 Marks) Mets ML co ‘Answer ALL Questions 28. a. Consider the folowing fragment of C code: moa float ij imis'70+j+2 ‘write the output ofthe compiler forthe above "C’ code and elaborate about the analysis and synthesis phase of compiler. (oR) . Construct optimized DFA. forthe regular expression (a° /6*Y‘abb(a/y'. 9 29. a4. Compute FIRST and Follow for the following grammar soa S>ABCD A-vale Boole CoCr D> Aaldle fi, Consider the following grammar oo32 Sola L3L5\S Construct eR most derivation end parse tree for (a,(a,4)). (or) 1b. Show the following grammar is LL(1) and parse the input string “baba”. Sola L>LS|S 30a. With your own example, show that the grammars LR(1) but notLALR, ?# # (oR) . Compute the operator precedence matrix, precedence relation and "= ¢ 3 precedence function for the following grammar and generate the stack Jmplementaton for the expression water * water + water. ‘Where GIRAFFE, ELEPHANT, TIGER, FOX are non-terminals and food, water are terminals. (GIRAFFE ~» ELEPHANT ELEPHANT-> ELEPHANT + TIGER | FLEPHANT—TIGER | TIGER TIGER ~ TIGER + FOX | TIGER / FOX | FOX FOX ~ food | water | (ELEPHANT) ‘1.aLi. Express the sematio rule for productions of Boolean expression write three “address code for £5 1O0||#> 2008 &ex!= ») fi, State the different ways of representing intermediate languages (or) ‘bi, Explain the translation scheme to produce three address code for assignment. 3 1 statements fi, Write three address code for the following expression at “we a)+(y+3)—(we rt yt3) 32, Consider the following classification metres: oe 253725 mn iye4 2 ma = 02-9)! ps m3 = 03-92)! (05 -¥2)s Interpret the instruction and generate three address code and DAG for the above express (oR) ‘bi, Consider the following code, find out the minimum number of registers." required to compile the given code (With optimization and Gi) Without optimization cnath d=c+a; ¥(e

You might also like