NPTEL Compiler Design Week 12 Assignment Answers 2024

NPTEL Compiler Design Week 12 Assignment Answers 2024

1. Backpatching is needed to generate intermediate code using

(A) Single pass
(B) Two passes
(C) Multiple passes
(D) None of the other options

Answer :- 

2. For the rule “S → while M1 B do M2 S1 ”, in three address code generation, which of the following has to be backpatched with M2 .quad?

(A) B.truelist
(B) B.falselist
(C) S1.nextlist
(D) No backpatching possible at this point

Answer :- 

3. For the rule “S → while M1 B do M2 S1 ”, in three address code generation, which of the following has to be backpatched with M1 .quad?

(A) B.truelist
(B) B.falselist
(C) S1.nextlist
(D) No backpatching possible at this point

Answer :- 

4. For the rule “S → while M1 B do M2 S1 ”, in three address code generation, which of the following is true?

(A) S.nextlist = B.truelist
(B) S.nextlist = B.falselist
(C) S.nextlist = S1.nextlist
(D) None of the other options

Answer :- 

5. In function call management, which of the following tasks are done by the caller when it calls the callee?

(A) Evaluate actual parameters
(B) Place actuals where the callee wants them
(C) Save machine state (current stack and/or frame pointers, return address)
(D) All of the above

Answer :- 

6. Which of the following options completes the three address codes (Line 5) for the function call z = f(x+1, y+1) + 1? 1. t1 = x + 1

  1. t2 = y + 1
  2. param t1
  3. param t2
  4. _
  5. retrieve t3
  6. t4 = t3 + 1
  7. z = t4

    (A) call f
    (B) call f, 2
    (C) call f, t1, t2
    (D) None of the above
Answer :- 

7. Consider the two statements given below.
S1: Intermediate code generation, though not mandatory, helps in retargeting the compiler towards different architectures.
S2: Syntax-directed schemes can be utilized to generate three-address code from the parse tree of the input program.

Choose the correct option from below.

(A) Only S1 is true
(B) Only S2 is true
(C) Both S1 and S2 are true
(D) None of the other options

Answer :- 

8. In a switch statement, to search for the matching case, jump table is suitable for

(A) Small number of cases
(B) Large number of cases
(C) Any number of cases
(D) None of the other options

Answer :- 

9. In three-address code, arrays are

(A) Not supported
(B) One dimensional
(C) More than one dimensional
(D) Supported via pointers

Answer :- 

10. Consider the following code segment.
begin
while a > b do
begin
x = y + z
a = a – b
end
x = y – z
end

One incomplete three address code for the above code segment is given below.
1: if a > b goto 3
2: goto 8
3: t1 = y + z
4: x = t1
5: t2 = a – b
6: a = t2
7: __
8: t3 = y – z
9: x = t3

Which of the following options completes Line 7 of the three address code given above?

(A) goto 1
(B) goto 3
(C) goto 5
(D) None of the other options

Answer :- 

Leave a Comment