R.M.K. ENGINEERING COLLEGE RSM Nagar, Kavaraipettai – 601 206 Question Bank for the Units –III to IV SE00 6thSemester – B.E. / B.Tech. BR00 Computer Science and Engineering SU00 CS8602 – Compiler Design Part-A (10 x 2 = 20 Marks) K Level CO S/A 1. Define synthesized and inherited attributes. K1 CO3 S 2. Give the SDD for a simple type declaration. K1 CO3 A 3. Construct a decorated parse tree according to the syntax directed definition, for the following input statement: (4+7.5*3)/2 K3 CO3 A 3. Draw the syntax tree for the expression a=b*-c +b*-c K3 CO3 A 3. Translate the arithmetic expression a*-(b+c) into syntax tree and postfix notation K3 CO3 S 3. Derive the string and construct a syntax tree for the input string “ceaedbe” using the grammar S->SaA | A, A->AbB | B, B->cSd | e K3 CO3 S 3. Construct syntax tree for the following assignment statement a:=b*-c+b*-c K3 CO3 A 4. What are the different types of Intermediate representation? K1 CO3 S 4. Convert the expression a * – (b + c) into three address code. K3 CO3 A 6. Draw the activation tree for the following code: int main() { printf(“enter your name:”); scanf(“%s”, username); int show_data(username); printf(“press any key to continue……”); ----} int show_data(char *user) { printf(“your name is %s”, user); return 0; } K3 CO4 A 7. What is a calling sequence? K2 CO4 A 7. What is a return sequence? K2 CO4 A 9. List the two functions of a memory manager. K1 CO4 S 9. What is the purpose of control link? K2 CO4 S 10. What are the goals of a code generator? K2 CO4 A 10. What is a register descriptor? K2 CO4 S 10. What is an address descriptor? K2 CO4 A Part – B ( 5 x 13 = 65 Marks) 11.a. Evaluate the expressions for the SDD annotated parse tree for the follow expressions. (13) a) 3 * 5 + 4n b) (3 + 4) * (5 + 6) K3 CO3 S 11.b. Develop the SDD to construct a syntax tree for a simple expression and construct the syntax tree for a – 4 + c. (13) K3 CO3 A 11.b. Develop the SDD to construct a syntax tree for a simple expression and construct the syntax tree for a – 4 + c. (13) K3 CO3 A 12.a. Explain the common forms of 3-address code and generate three address code for the following while loop (13) a=3; b=4; for(i=0;i<n;i++) while(i<n) { a=b+1; a=a*a; i++; } c=a; K2 CO3 S 12.a. Describe the various forms of three address codes and generate three address code for the following segment (13) switch (ch) { case 1 : c = a + b; break; case 2 : c = a – b; break; } K2 CO3 S 12.b. Give translation scheme for Assignment Statements and convert the following expression into Three address codes and represent the same in the K3 CO3 A form of Quadruples, Triples and Indirect Triples. a=b*–c+b*–c (13) 13.a. What are the different storage allocation strategies? Explain. (13) K2 CO4 S 13.b. Describe about the contents of activation record. (13) K2 CO4 S 13.b. Explain Heap Management in detail. K2 CO4 S 14.a. Explain on Lexical Scope Without Nested Procedures (13) K2 CO4 S 14.b. Explain in detail about Run-time Storage Organization(13) K2 CO4 S 14.b. Discuss about the various addressing modes of instruction set and cost evaluation procedure (13) K2 CO4 S 15.a. Give SDD for expression grammar with inherited attributes to evaluate an expression 1*2*3*(4+5) (15) K2 CO3 S 15.b. Generate code for the following three address statements: (13) t1 = a – b t2 = a – c t3 = t1 + t2 d = t3 + t2 and explain the status of register allocation with register description and address description. K3 CO4 A 15.b. Generate code for the following three address statements: (13) t1 = a + b t2 = c + d t3 = e – t2 x = t1 – t3 and explain the status of register allocation with registers R0, R1 with register description and address description. K3 CO4 A K3 CO3 A K3 CO3 S (13) Part – C ( 1 x 15 = 15 Marks) 16.a. Suppose we have a production A B C D. Each of the four non terminals has two attributes s, which is synthesized, and i, which is inherited. For each set of rules below, check whether the rules are consistent with (i) an Sattributed definition. (ii) an L-attributed definition (iii) any evaluation order at all. (15) A.s A.s A.s A.s B.i C.i D.i 16.a. = B.i + C.i = B.i + C.s = B.s + D.s = D.i = A.s + C.s = B.s = B.i + C.i and D.i = A.i + B.s Apply the S-attributed definition and constructs syntax trees for a simple expression grammar involve only the binary operators + and -. As usual, these operators are at the same precedence level and are jointly left associative. All nonterminal have one synthesized attribute node, which represents a node of the syntax tree. Production: E→E+ T, E →T, T→ ( E), T→ id/ num (15) 16.a. Below is a grammar for expressions involving operator and integer or floating-point operands. Floating-point numbers are distinguished by having a decimal point. K2 CO3 S Give an SDD to determine the type of each term T and expression E. Extend your SDD to translate expressions into postfix notation. Use the unary operator intToFloat to turn an integer into an equivalent float. (15) 16.b. Construct Activation Trees for the fibonacci sequence 1,1,2,3,5,8, ... defined by f(1)=f(2)=1 and, for n>2, f(n)=f(n-1)+f(n-2). Explain the observations about these procedure calls K3 CO4 A 16.b. Explain how access links are implemented by adding pointers to each activation record program main; var a:int; procedure p; var d:int; begin a:=1; end; procedure q(i:int); var b:int; procedure s; var c:int; begin p; end; begin if (i<>0) then q(i-1) else s; end; begin q(1); end; K3 CO4 S 16.b. Explain the implementation of accessing nonlocal variables using display concept program main; var a:int; procedure p; var b:int; procedure q(); var c:int; K3 CO4 S begin c:=a+b; end; begin q; end; begin p; end;