0% found this document useful (0 votes)
3 views7 pages

NPTEL Online Certification Courses Indian Institute of Technology Kharagpur

This document contains an assignment for a Compiler Design course, specifically focusing on multiple-choice questions related to syntax-directed translation and three-address code generation. It includes 13 questions with answers and explanations regarding Boolean expressions, control flow, and array handling in code generation. The assignment is part of the NPTEL Online Certification Courses offered by the Indian Institute of Technology Kharagpur.

Uploaded by

rp20129421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

NPTEL Online Certification Courses Indian Institute of Technology Kharagpur

This document contains an assignment for a Compiler Design course, specifically focusing on multiple-choice questions related to syntax-directed translation and three-address code generation. It includes 13 questions with answers and explanations regarding Boolean expressions, control flow, and array handling in code generation. The assignment is part of the NPTEL Online Certification Courses offered by the Indian Institute of Technology Kharagpur.

Uploaded by

rp20129421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

NPTEL Online Certification Courses Indian

Institute of Technology Kharagpur

Compiler Design
Assignment- Week 11
TYPE OF QUESTION:MCQ
Number ofquestions:13 Total mark: 13 X 1 = 13

1. For the rule S  L := E, if L is a single variable, L.place is equal to

(A) Null
(B) Some value
(C) Constant
(D) None of the other options
Ans: B
Solution:

2. For Boolean variable B, B.truelist contains

(A) List of locations at which B is true


(B) List of locations to jump to if B is true
(C) List of locations at which B is true and the locations to branch to
(D) None of the other options
Ans: A
Explanation:

In syntax-directed translation for Boolean expressions, a truelist


(B.truelistB.truelistB.truelist) is a list of locations in the generated intermediate code
where a jump occurs if BBB evaluates to true.

• (A) "List of locations at which B is true" is correct because


B.truelistB.truelistB.truelist stores the positions in the code where the control
needs to be updated when BBB is true.
• (B) "List of locations to jump to if B is true" is incorrect because it refers to the
target of the jump rather than the list of jump instructions that need
backpatching.
• (C) "List of locations at which B is true and the locations to branch to" is incorrect
since B.truelistB.truelistB.truelist does not include target locations, only the
positions that need to be filled later.
• (D) "None of the other options" is incorrect since (A) is correct.

3. When generating code for the Boolean expression "(x ≥ y) AND (p ≠ q)", which locations
are left for back patching?

a) Falselist of x≥y
b) Falselist of x≥y and falselist of p q
c) Falselist of x≥y, falselist of p q, truelist of p q
d) Truelist of x≥y, falselist of x≥y, truelist of p q, falselist of p q

Ans: B
Explanation:

4. In three-address code, arrays are

(A) Not supported


(B) One dimensional
(C) More than one dimensional
(D) Supported via pointers
Ans: C
Explanation:
5. For three address code generation of “B  B1 or M B2”, M.quad is used to backpatch

(A) B1.truelist
(B) B1.falselist
(C) B2.truelist
(D) B2.falselist
Ans: B
Explanation:
6. For the rule B  B1 and B2, the operation "B1.false = B.false" requires two passes as

(A) B1.false is not known


(B) B.false is not known
(C) Both B1.false and B.false are unknown
(D) None of the other options
Ans: B
Explanation:

7. In the rule C→C1 AND NC2 the non terminal N is used to remember the start address of:

(A) C
(B) C₁
(C) Both C₁ and C
(D) None of the other options
Ans: B
Explanation:

8. In the rule S  if B then M S N else M S, N is used to generate a jump after

(A) then-part
(B) else-part
(C) both then- and else-part
(D) None of the other options
Ans: A
Explanation:
9. In the rule S if B then M S1, M holds the start address for

(A) S1
(B) S
(C) B
(D) None of the other options
Ans: A
Explanation:
10 For three address code generation of rule “S  while M1 B do M2 S1”, B.falselist is
. backpatched with

(A) M1.quad
(B) M2.quad
(C) Cannot be backpatched at this point
(D) None of the other options
Ans: C
Explanation:

11.

In three-address code (TAC), accessing an array element typically requires:

(A) Direct assignment without indexing


(B) Computing an address using the base address and an offset
(C) Using only registers without memory references
(D) None of the other options

Ans: B
Solution:
In TAC, arrays are accessed using their base address and an index offset.
The address of an array element is computed as:
Address=Base Address+(Index×Element Size)
This ensures efficient memory access and supports multi-dimensional arrays using similar
calculations.
12.

In the rule S → while M1 B do M2 S1, the non-terminal M2 is used to remember the start
address of:

(A) S
(B) B
(C) S1
(D) None of the other options

Explanation:

• In three-address code (TAC), loops require backpatching to manage control flow.


• The while-loop executes S1 repeatedly as long as B evaluates to true.
• M2 stores the address of S1, so execution can jump back after completing one
iteration.

Why Not the Other Options?

• (A) S → Incorrect, because S is the entire statement, not just the body.
• (B) B → Incorrect, because B is a condition, not the loop body’s start point.

13.

For a Boolean expression B, the attribute B.falselist contains:

(A) List of locations where B evaluates to false


(B) List of locations to jump to if B is false
(C) List of locations where B is false and the locations to branch to
(D) None of the other options

Ans: B

END of Assignment

You might also like