You are on page 1of 24
Chapter 1. The lexical analyzer (@) is called the backend of the compiler js called the frontend of the compiler (6) is called the intermediate stage of the compiler (d) none of the above 02, In the lexical analysis phase of a compiler (a) lexemes & tokens are the same jog (p) lexemes & tokens have n0 relationship es (6) lexemes are formed from tokens y saytokens are formed from lexemes aa analyzer (a) tokens are larger in size than lexemes (b) lexemes rae more storage space than tokens yi (©) lexemes as occupy the same amount — (@) lexemes & tokens both be accommodated in a single by time of can storage 04. Handling macro expansion is taken care in the (a) syntax analysis phase Ww © (b) semantic analysis phase Jf “oh % wo na 0. ica! , i oat (© during load time @ pres (@ by a modification of the fina es generated bY the compiler fO) ee ! aq te entire source prog, |) ro jn the symbol table during cons (a) Semantic analysis es ca (b) Syntax analysis griexical analysis ~ the Ie (@) Code generation phase oo str 07,1n some programming languages there js, ee distinction between reserved words 4 variable names. This feature can be handle ore (ay completely by the lexical analysis be (b) only during the semantic analysis phase ps3 by the syntax analysis passing informaix i. back to the lexical analysis @ec (4) cannot be allowed in any HLL. f 08. Type checking is handled by (a) The lexical analyzer Rey (b) The syntax analyzer he $F The semantic analyzer ue (a) (d) Register optimization (©) code generation phase 09. The formal model used for the les c ? none of the above analyzer is ‘ 4) the finite automata i 05, Macros & preprocessor directives are handled (b) the push down 2) in the lexical analysis phase (©) the two push di oe (b) during the linking of the object modules (@) the turing ie oe machine at A SSL FU TS Q Scanned with CSc (At can only handle regular expressions . The lexical analysis (a) can determine all the control statements of structured programming for structural “ee (Pea determine if a variable is defined constructs before it is used n check if an identifier appears more thai 10 times in the source program mung ls | @can check if the number of actual & many HL. formal parameters in functions are the | same numbers. dby | om 12, Regular expression can be used to model in the lexical analysis (a) The structure & lexemes with fixed length identifiers excluded |) The structure of tokens fo (©) The structure of tokens but not lexemes (d) The structure of lexemes with variable length identifier in ength identifier ine See in case of | 13. The time taken by the lexical analysis phase lysis in the usual compiler fo the largest in a computer among all @ tt can check if the parenthesis phases, Sos Peto radon Ye dite ~UEG- (b) is the mt in computer among alle () It can check for any pair of matching phases vee See parenthesis “ae (©) is larger than what the syntax wine (© lt can check the structure of if-then-else takes but less than that of the semantic constructs Nee " analysis takes (4) is smaller than the time taken for both syntax & semantic analysis phases 14,In the internationalization of a compiler, where the source program can be in different natural languages GY is sufficient to change and adjust the front-end or lexical analysis of a computer (b) The entire computer has to be re-written (©) The backend of the computer cannot be reused. (d) The number of registers needed can vary 15. The listing of the source program by a ler occurs during com Maia (b) the syntax analysis phase lexical analysis phase (©) the semantic analysis phase (@) during the code generation phase 16.Comments in the source program to a computer are deleted by Wy The lexical analysis (b) The semantic analysis, (c) The code generation (d) The code optimizer chen Wayanad Scorned with Camco 17. The lexical analysis & the syntax analysis can be focused together into one phase (@) This has:the advantage that a very large BNF grammar results GFSince regular grammars are simpler than context-free grammars and we can have a Separation of concems between lexical concerns & syntax concerns, (©) The complexity of the frontend decreases (@) None of the above 18. The # define C compiler J by the lexical analysis / (b) by the syntax analysis (©) by the semantic analysis (A) by the code optimizer directive in C is handled on a 19, A wants to set a variable ‘are’ to 11)6, t does the following (1) he uses a directive # define are 1116 (2) he uses an initialization statemen, ‘main’ are = 0; Choose the correct statement (#) (1) is done during lexical analysis time g (2) during ‘exe’ time sol (b) Both (1) & (2) are handled during + cay time (©) Both (1) & (2) are handled by the synia, 5 analysis ‘ (@ Both (1) & (2) are handled by the semantic analysis 20. Comments in the source program are. (a) Deleted by the lexical analysis, (b) Deleted by the syntax analysis (©) Stored in the symbol table (@ Embedded in the object code in coded form a) Scanned wth Camicarner iE are? e Lg hy OX ————— o Fito ans: ©) iy a ‘the lexical analyzer is the frontend of th compiler which teads the source program. maly si, neg fans d durin, First of all the source program is broken up 8 “exe into lexemes, these are classified & ; converted to tokens. Y the sy a Ans: ) lled by consider a lexeme for an identifier, it can be very large where as the token is of fixed size. are Jog Ams: (@) “ | gol: The frontend of the compiler takes care of macro expansion. in codeq | 95 Ans: (@) Sol: The lexical analysis phase takes care of handling macros and _ preprocessor directives. 06. Ans: (c) Sol: In the lexical analysis phase identifiers are stored in the symbol table & mapped to tokens. 07, Ans: (c) Sol: In a language the PL/I on the IBM ‘sis co-operates mainframe the syntax analy: operat with the lexical analyzer to distinguish between variable names & reserved words. $8. Ans: (o ol: Type ‘Type checking is context sensitive feat ‘ that can, ‘only be handled by the s analyzer, ™ 09. Ans: (a) So ‘Though all the formal models can be used. the finite automata is generally used to ‘model the lexical analyzer. 10. Ans: (a) Sol: The lexical analysis is modeled by the finite automata and parenthesis matching & checking the structure of if-then-else statements is a context free feature which is not regular. 11. Ans: (&) Sol: This feature can be handled by a finite automata, the remaining choices are context- free or context sensitive & not regular. 12. Ans: (a) Sol: The structure of all lexemes in some programs can be verified & described by @ regular grammar. 13, Ans: (a) Sol: The lexical analysis time is determined by the V/O time in the computer. As the source program is normally stored on the disk or other backup store there is a bottleneck of VO time, So the front end of the computer takes the maximum amount of time. am aan ot Tapa AERIS Scorned with Camco 236 Ey F ip? 17, Ans: (b) Sol: It is sufficient to change or modify the front | Sol: The separation of concems makes ‘ee D op' end. The entire compiler can be reused, complexity less. i @ 3 @) 15. Ans: (a) 18, Ans: (a) a o* Sol: The listing is merely done by outputting | Sol: This is a preprocessor directive and ean be 8 Whatever is read in during lexical analysis handled during lexical analysis time, ! s 16. Ans: (a) 19. Ans: (a) @ Sol: The squeezing out of comments ean be done | Sol: (1) is a preprocessor directive & choice Q ‘ in the lexical analysis phase as the deletion 3 an crecuable Seema of comments & checkit i e * recking of their structure 20. Ans: (a) bv can be modeled by regular expressions, Sol: Comments are deleted & squeezed on | (a)! during lexical analysis. ) (OF @ (3. The (a) () © @ Yn (a g (ec f Scanned wth Camicarner o1. Top down parsing techniques (@) simulate a leftmost derivation — (b) simulate the reverse of a leftmost derivation (©) simulate a rightmost derivation © 0 (@ simulate the reverse of a rightmost derivation é 02. Every LR(0) grammar is * (2) LR() grammar (b) may be LR(1) grammar (c) sometimes not LR(1) grammar (d) none of the above 03. The LL(1) & SLR(1) grammars are (a) the same (b) LR(1) is more powerful (c) SLR(1) is more powerful (d) incomparable -~ 04. The operator precedence technique (a) simulates building the parse tree top down Gp) simulates building the parse tree bottom up (c) simulates the reverse of a leftmost derivation (d) none of the above anes ———I Parsing Techniques chon Prna enter Cheonl Wayanad Veg» Tra HOT 05. The type of Cquate states that can arise the LR(1) technique are “se (a) shift ~ reduce conflicts — (b) shift shift conflicts (©) reduce ~ reduce conflicts (@) none of the above 06. The grammar S$ — SS |aa| e vot ie (a) is LR(O) (b) is SLR) (c) is LALR() (d) none 07. The grammar ST] ela, T+Sla (a) is ambiguous and hence not SLR(1) (b) is unambiguous & LR(0) (©) isnot LALR(1) but is SLR(1) (@ is LRG) 08. When a LR(1) machine is constructed for the if statement grammar S—if(®)S Sif (®)S else S Sa Ei (a) there will be no inadequate states (0) the dangling else ambiguity does. not arises Ne the dangling else ambiguous can be resolved by using the fact that else should belong to the nearest if (4) none of the above Avent | hr Maer ne with CamScanmer 09. The grammar SOTA As el+TA Tiln (@ is LL(1) (®) is LAER) i (©) LR() but not LALR(1) @none 10. In the grammar ESE=E/E+Eli When we construct a SLR(1) machine (@) No inadequate states parse. Inadequate states can be resolved using the associativity & precedence of = & +. (©) Inadequate states cannot be resolved. (d) None of the above. 11. The grammar $ — a is (@) LLG), LR(1), LALR(1), LR(0), SLR(1) & operator precedence. (b) LR() but not LL(1). (©) LRU) & LLC) precedence. (d) None of the above, but not operator 12. The grammar S— while (E) $ a Eva for nested while statements (@) isnot LR(1) (b) is not SLR(1) (©) is not LALR(1) (d) is LR(O) soa ai 4 do-while statements 5 for nes ut not LALR(D) os ee put goeSLROY is AN put got RO) ), (oun 2, Bo dl eis “4 ne (©) not Luay~ ‘ ()LRO) (d) None 15. The grammar SOFA AoeltTA Foi reflects that (a) Tis left associative. af) 1 is right associative. (©) Cannot deduce associates from i grammar. (@) none of the above, : 16. The grammar Sradale A>abS|c @)is ambiguous ()is Lay ©is not nay !) none Scanned i ith Camscarner ne ar 13, Te os while © Bee ea B Ley ‘the pe following grammar ‘AoBbICd po elaB it caecle (ois eft recursive and hence not LL (1) (right recursive and henee not LL(1) @ LLG) {@ none of the above jg. When there are no ShifVReduce conflicts in CLR(1), in the corresponding LALR(1) (@) No Reduce Reduce conflicts (0) No Shift - Reduce conflicts 5 —~ (©) Shift — Reduce conflicts may occur (@ none of the above 19, Bottom Up parsing techniques 21. Number of i f inadequate states in DEA with LR(O) items is fl S| gE 22. The above grammar is @IRO @SLRU) © LLG) A (@None ae 23. The grammar G is Program —» begin d semi X end X— dsemiX|sY Y—semis¥ |e (@) The grammar is ambiguous and hence not LL) (b) The grammar is LALR(1) but not LL(1) (©) The grammar is LR(0) but not LALR(1) (2) Simulates a leftmost derivation 5 () Simulates the reverse of a leftmost AGH Ton gemma CAA) derivation. 24, The grammar (©) Simulates a rightmost derivation 1.8 AB (Simulates the reverse of @ rightmost DA Aa derivation 3.898 4 ASE 20. Synthesized attribute ean be simulated by 5.B>bB (a) LL(1) Grammar ee A ol? 6.Bo4e (b) LR(1) Grammar es \ if a LL (1) parsing table is constructed for (c) Ambiguous Grammar 4 a above grammar where T (X, ©) represents (@ None e 6 production sed to expand. varible X on yA ookahead ‘2°, which of the following is te. Common Data for Q.21 & Qu arian Consider the grammar given Belov" (i T@S)=34 S—+E# Bak Gi) T(A,S)=4 E>TIET Mw (TB9=61 To Tale win oe cpa opal Fone Boa Scanned wth CamScarner (a) @) & (iv) are correct (©) @ alone is correct © (i) & (iii) are correct (@) @, Gi) & (iv) are correct 25. Which of the following suffices to convert 3% arbitrary unambiguous context free grammar toa LL(1) grammar? (a) removal of left recursion \< () factoring the grammar alone ye (©) removing left recursion and factoring the i" uf grammar ve! none of the above 26. Construct the LALR(1) set of items for the grammar: Siss S+48S|a Then, identify, in the list below, one of the LALR(1) sets of items for (a) [S—a., $] (©) [S++8S., $+a] (b) [S—a., +a] @[S+88,, $] 27. Consider the grammar S—(S)|[S]|SS |e is (@) left recursive Pombiguous 28. Consider the grammar given below: S—AS|b A—SAla (b) right recursive (d) unambiguous The grammar is OL) (i) LR QL 4G) LR @ jae i o@ wre correct ome “ i (ii) are not correct @ @o® @ goxSx IXTE € 29. porxl* Kio mmar is i ere (©) LRG) : ic t LLC) ambi (©) SLR() but no 8 iB ‘ mar ( 30. Consider the Gram! s (9/810 ois tn the goto graph of LR(O) items, the mag of inadequate states are (b)2 @o A (©)3 . 31. Construct the LALR(1) sets of items for 4] grammar: 3 sins S—*SS|a ‘ Then, identify, in the list below, one of LALR(1) sets of items for (a) [Sa,, 8] (© [S*SS,, $+a] (b) [S—a,, +a] (d) [S*s8,,§] 32. The grammar ESE*E EsE-E - Esa ig (@) LR) ©) SLR) )LRO) None ofthe above Scanned wth Camicarner y BCE A Bd| Cd Bocd 241 Coad (a) not LLC) (©) Cannot say ~(6) LLC) (d) none ys.Consider an SLR) & LALR(1) tables which of the following is true? , (a) Shift entries are different (b) Reduce entries are same (©) Goto entries are different ¢éy Error entries are different loys Tbe, . 35, Consider the grammar $ —> Ce, C eC | 4 (a)ItisLL(1) ~~ (b) It is SLR(1) but not LL) (c) It is LALR(1) but not SLR(1) (@ Itis LR(1) but not LALR(1) 36. Which of the following statement is true? (a) Every LL(1) is SLR(1) (b) Every LL(1) is LR(0) (c) Every LL(1) is LALR(1)_ . 07 (d) None of the above - ys 37. Reduce 1/Reduce 2 conflict and shift/reduce 3 conflict are resolved in favor of (a) Reduce 1 and reduce 3 (b) Reduce 2 and shift (c) Reduce 2 and reduce 3 fone of these 38. The following grammar is so Aa/bAc/de/bda Aod Doerr oe? ar wake Ps Tams mapa Pane Bhabanenwat Lack a = guous (b) SLR) (© LALR() (@) LALR() but not SLR) 39. Assertion al: There exist grammars that are LALRU) butnot SLR). Reason [r|: The i grammar bel butnot stRC1, iar below is LALR(1) S— AaBb| BbBa AseBoe (@) Both (a) and (¢) are true and (f) is the correct reason for (a). (b) Both (a) and (¢) are true and (r) is not the correct reason for (a). (©) Both (a) and (r) are false. @ (@)is true but (0) is false, 40. Consider the grammar EST+E|T Tid Choose the correct statement (@) + is left associative (bY is right associative (c) + cannot have associativity (@) The grammar is ambiguous 41. Consider the grammar EI>E E E+E|id Choose the correct statement (a) + is left but not right associative (b) + is right but not left associative (6) the grammar is unambiguous (4) + can be either left or right associative el om Scorned with Camco Solutions ae 01, Ans: (a) Sol: Top down parsing techniques sim leftmost derivation. ates ® 02, Ans: (a) Sol: Every LR(0) grammai LR(1) grammar. 1 is compulsorily * 03. Ans: (d) Sol: There exist grammars that are LL(1) but SLR(1). There exist grammars that are SLR(1) but not LL(1). So LL(1) & SLR(1) grammars are incomparable. not 04. Ans: (b) Sol: The operator precedence technique is 4 bottom up parsing technique. It simulates the reverse of a rightmost derivation & building the syntax tree bottom up. 05, Ans: (a) & (c) Sol: Both shift-reduce & reduce-reduce conflicts can occur ina LR(1) machine. 06. Ans: (d) Sol: The grammar is ambiguous S — (S5)' 4 c*®#_+, 5 The string ¢ has an infinite number of derivations in the grammar, So, the gramm; » ar is ambiguous. No ambiguous gtammar be LR. = Hyderabad ets pho + Pane Bhataaan teste Pata, Le gn Anse @ ar is ambiguous. eee | 7 grat syation it : tion in th sol: Consider He derivation im the ing sate E oa or $s has more than ong wring “® ‘The ne grammar is jous grammar can be gy 1 mbiguous, so, t No ambig™' LR): ans) & C varieties of ‘i? statements wit, se beter the dangling else Problen, | tt toh +B) if (E)S else 9 es ip derivation trees. It is not clear as to wa L the else belongs to the inner “if o,, | outer “if”. ao: ! Sol: ‘The standard and accepted way to tg, the dangling else problem is to aljgy | else to associate with the nearest if, 09, Ans: (a) & (b) Sol: The predictive parsing table for the is AS4TA Soe [>]=[2] Toi|Ton as} oo there is no conflict in the pri Parsing table so the grammar is LL(!)- TI he LR) machine for the gram 81Ven below, Ealuru «Chana ne with CamScanmer Go TA h. ta Ans: (a) “ Sol: The ‘Srammar is trivially a LL(1) grammar & also a LR() grammar. Hence it is Sutomatically SLR(1), LALR(1) & LR(1). 12. Ans: (ay Sol: Consi I: Consider the LR(O) machine for the grammar. issue So wees PES wes Stat| 8 ng a i | Wei, | | "Sig j ER ey | & i fASSeTAS wit, | re grammar is LR(O) as there is no = Te jetequate state. Hence the grammar is 8 tp | paLR()- Whethe | we te pe ns (0) grammar is ambiguous esolve (1) It is not clear as to whether = is left W the | sscociative or right associative on the sentence ‘i (2) It is not clear as to whether + is left nmr associative or right associative in the sentence ‘i+iti’; (3) The precedence of = & +are not clear in the sentence i=iti; So not only have the associativity of the operators to be fixed but also the ve relative precedence of the re Once these are fixed the grammar 8 be unambiguous. There is no conflict in the LR(0) machine. So the grammar is LR(0). Hence it is automatically SLR(1), LALR(1) & LR(1). 13. Ans: (a) Sol: The predictive parsing table for the grammar is given below. do S>d0S while(E) E As there is 10 conflict in the predictive parsing table the grammar is ey Consider the LR(O) machine for the grammar. ne with CamScanmer

You might also like