QUESTIONS RELATED TO UNIT I, II And III UNIT I 1. Define the role of input buffer in lexical analysis 2. Write regular expression to generate identifiers give examples. 3. Define the elements of production. Give examples. 4. Discuss brief lexical phase error. 5. Discuss neatly the language for specifying lexical analyzers. 6. Define Compiler. What are the phases of the Compiler? Explain with a neat diagram. 7. What are Compiler Construction Tools? Explain its specifications in detail. 8. Explain the role of lexical analyzer in detail. 9. Define finite automata. Explain its types in detail. 10. Construct NFA, DFA for the expression bb*. 11. Explain in detail about error detection and recovery. 12. Consider the following fragment of C code: float i, j; i = i * 70 + j + 2; Write the output at all phases of the compiler for the above C code. 13. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail. 14. Explain the different phases of a compiler, showing the output of each phase, using the example of the following statement: position : = initial + rate * 60 15. What is cross compiler? How is bootstrapping of compiler done to second machine. 16. Write short note on a) Incremental compiler b) Bootstrapping compiler. 17. How lexical analyzer removes white spaces from a source file. 18. Give lex specification in details. UNIT II 19. Construct a parse tree to the string-(id+id) using left most derivation. 20. What is ambiguous grammar? Eliminate ambiguities for the grammar: E -> E + E E E (E) id.
21. Define Parser. Construct the derivation of parse trees 22. Distinguish between parse tree and syntax tree. 23. Consider the following grammar. S -> 0A 1B 0 1 A -> 0S 1B 1 B -> 0A 1 S Construct leftmost derivations and parse trees for the following sentences i. 0101 ii. 1100101 24. Explain top-down parsing. Give example. 25. Explain the principle of predictive parser. Give an example. 26. Explain the different moves of LR Parser on id* id + id. 27. Construct SLR parsing table for the following grammar. S ->AS b A -> SA a 28. Construct predictive parsing table for the following grammar. E -> T E' E' -> +T E' e T -> F T' T' -> *FT' e F -> (E) id 29. What is an operator grammar? Give an example. 30. Write an operator precedence parsing algorithm. 31. What are the advantages and disadvantages of operator Precedence parser? 32. Write a note on the specification of a simple type checker. 33. What is a type expression? Explain the equivalence of type expressions with an appropriate examples. 34. What is recursive descent parser? Construct recursive descent parser for the following grammar. E -> E + T T T -> T* F F F -> a b 35. Define LR(k) parser. Draw and explain model of LR parser. 36. Write LR parsing algorithm.
37. Consider the following grammar : G -> S $ S -> AM M-> S A -> ae baa E -> ab ba ε B -> be abb Is the above grammar LL(1). If so, construct LL(1) parsing table. If no, explain why? 38. Find FIRST and FOLLOW of the following :- a) S -> aab ba ε b) S-> v XUW UV uwv A -> aab ε U -> w WvX SUVW SWX ε B -> bb c V -> x wx ε W -> w UXW X -> yz SuW SW 39. Are following grammars LL(1). (1) E -> E+T T (2) E -> E + T T (3) S-> AaAb BbbA (4) S-> ietss T-> T*F F T -> TF F A-> ε S -> es E F -> (E) id F-> F* a b B-> ε E->b (5) exp->atom list (6) decl -> type list atom-> num id type -> int float list->(exp ) list -> id,list id exp ->exp exp exp 40. Construct LR(1) parsing table for following : S->aBD AB DAC b A-> SCB SABC CbD C ε B->d ε C->ADC c D->SaC SC fg 41. Construct LR(0) parsers for each of the following: a) S->cA ccb b) S->aSSb asss c c) A->cA a d) B->ccB b 42 Find canonical collection of LR(0) items for following grammar : E-> E+T T T->T*F F F->(E) id 43 Construct LALR items for following grammar :
E-> E+T T T->T*F F F->(E) id 44. Construct LALR parsing table for following grammar: S-> B B-> begin DA end D-> Dd; ε A-> A;E ε E-> B S 45. Write LEX specifications and auxiliary routines, if any, to read source text file and display total number of characters, words and lines in the file. (16M) 46. Write a CFG to parse an assignment statement consisting of arithmetic expression on RHS of the assignment. +, * and / operators needs to be supported with + having higher precedence and left associative and * and / have equal precedence but lesser than + and both are right associative. Is your grammar suitable for top-down table driven parser? If not, write equivalent suitable grammar. Compute First and Follow sets of non - terminals of the CFG. (10M) 47. Construct LALR parser table for the following CFG S -> A = B S -> B B -> A A -> * B A -> I Here, I (representing identifier), * and = are terminal symbols, S is the start symbol and A & B are non -terminals. Resolve the conflicting entries, if any, in the parser table and justify. Show the moves of the LALR parser for the following input. *p = *q (18M) 48. How YACC handles different types of conflits in parser? (4M) 49. Construct SLR parser for following grammar: [8] S a SS b S a SSS S c Show moves of above parser on one valid input string and one invalid input string. 50. Explain the use of LR Parsing method. 51. Whether lexical analysis detects any errors? Explain with example. 52. Explain the following : i) token. ii)pattern. iii) lexeme 53. Explain Recursive Descent parser with an example 54. What is Shift-Reduce and Reduce-Reduce conflict? How these can be resolved? With examples explain in which condition S-R and R-R conflict can occur in SLR, canonical LR and LALR parsers. (Make use of LR(0), LR(1) items). [10] UNIT III 1. Write the function of syntax directed translation. 2. Write semantic actions to the set of procedure. S->E$
E ->E+E E->E+E E->(E) E->I I->I digit I->digit. 3. Explain the implementation of syntax directed translators. 4. Write short notes on the following: (a) S-attributed definitions. (b) L-attributed definitions. (c) Dependency graph. 5. Write an ATG for floating point value of a decimal number given by following grammar : Dnum -> num. num num -> num digit digit digit -> 0123456789 6. Consider following ATG : Production Semantic Rule S -> ABC B.u = S.u ; A.u =B.v + C.v ; S.v = A.v A ->a A.v = 2 * A.u B -> b B.v = B.u C-> c C.v = 1 Draw the parse tree for the string abc, draw dependency graph, describe the order of evaluation, Suppose S.u=3 then what is the value of S.v when evolution finished. 7. Explain the need of semantic analysis. Position of type checker. 8. Explain synthesized and inherited attributes 9. What do you meant by attributed translation grammar (ATG)? What are synthesized and inherited attributes? What type of attribute (synthesized or inherited) will be required in C and PASCAL to enter in the symbol table the type information of variables appeared in declarative statements? Variables may be of simple types such as integers and float or array of simple types. Write the ATG for both the languages.(8m) 10. Generate annotated parse tree for following expression: [6] a*b-c/e + f 11. Explain bottom-up evaluation of L-attributed grammar(6m)
12. What is typecasting? What changes should be made in the semantic analyzer to add typecasting? (6M) 13. Explain Translation Scheme and Syntax Directed Definition with example.(8m) 14. Explain Bottom up evaluation of S-Attributed Definiton.(6M) 15. Write three address code to the statement A=-B*(C+D). 16. Write the quadruple, triple, indirect triple for the statement a: = b * - c + b * - c. 17. Give sequence of 3-address code for following in form of quadruples, triples and indirect triples 1. 2+3+4+5 2. 2+(3+(4+5)) 3. a*b+a*b*c 4. a[a[i]]=b[i[2]] 18. Give three address code for 1. read a 2. read b 3. if b=0 then 4. b=1; 5. else 6. do i. temp = b; ii v = a-a b*b iii a = temp; 7. while (b=0) 8. write (a) 19. Write CFG and semantic actions to parse and handle procedure calls and returns. Show the intermediate code for the following source statement in a) Quadruples and b) Triples notations. a = func (p, q, r); 20. What are Marker non-terminal symbols? Explain their significance for generation of intermediate code for flow - of - control statements UNIT I (Rest Part) 1. Explain the advantage of indirection in symbol table. 2. Explain the formulate of activation record.
3. Write notes on implementing block structured language. 4. What is an ordered and unordered symbol table? What is the function of symbol table in the compilation process? Explain. 5. What are the various attributes of a Symbol Table. 6. Compare three different storage allocation strategies. 7. Discuss the Display Mechanism used by the Pascal compiler to handle access to non - local names with adequate illustrations. [10] 8. Compare static scope with dynamic scope. Illustrate with suitable examples. [8] 9. What do you meant by activation record? With a neat sketch, describe the activation record used by a C compiler. [8] 10. With suitable examples explain various parameter passing methods. Also explain the mechanism needed to support procedure parameter. [10]