Machine-translated by Google. Questions are authored in English.
Top

Intermediate Code Generation Questions and Answers

1.

Consider the following pseudo-code.

L1: t1 = −1
L2: t2 = 0
L3: t3 = 0
L4: t4 = 4 * t3
L5: t5 = 4 * t2
L6: t6 = t5 * M
L7: t7 = t4 + t6
L8: t8 = a[t7]
L9: if t8 \(\lt\)= max goto L11
L10: t1 = t8
L11: t3 = t3 + 1
L12: if t3 \(\lt\) M goto L4
L13: t2 = t2 + 1
L14: if t2 \(\lt\) N goto L3
L15: max = t1

Which one of the following options CORRECTLY specifies the number of basic blocks and the number of instructions in the largest basic block, respectively ?

Exam Year(s)

GATE CS - 2024,

Answer: D

There are 7 basic blocks, and the largest has 6 instructions.

Leaders are the first statement, every jump target and every statement after a jump. That gives L1, the targets L3, L4 and L11, and the statements after the conditional jumps, L10, L13 and L15. The blocks are:

  • L1-L2 (2)
  • L3 (1)
  • L4-L9 (6)
  • L10 (1)
  • L11-L12 (2)
  • L13-L14 (2)
  • L15 (1)

So 7 blocks, the largest L4 to L9 with 6 instructions. Missing the leader at L3 (a jump target) gives 6 blocks with a 7-instruction largest block; missing L10 merges it into the L4 block.

Please log in or register to report this question.

2.

Consider the following expression: \(x[i] = (p + r) * -s[i] + u/w\). The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6).

(0)+pr
(1)
(2)uminus(1)
(3)
(4)/uw
(5)+(3)(4)
(6)
(7)=(6)(5)

Which one of the following options fills in the missing entries CORRECTLY?

Exam Year(s)

GATE CS - 2024,

Answer: A

The missing triples are (1) =[] s i, (3) * (0) (2), (6) []= x i.

Triple (2) applies uminus to the result of (1), and the expression negates \(s[i]\), so (1) must fetch the array element: =[] s i (an indexed read). The product \((p + r) * -s[i]\) multiplies the results of (0) and (2), so (3) is * (0) (2), and (5) then adds \(u/w\) from (4).

The target \(x[i]\) is an indexed location, so (6) is []= x i (an indexed write), and (7) assigns the value from (5) to it.

Options with - in (3) subtract where the expression multiplies, and options with []= in (1) write to s instead of reading it. Putting (5) in triple (6) is wrong because the index of x is i; the value (5) is supplied by triple (7).

Please log in or register to report this question.

3.

Consider the following statements about the use of backpatching in a compiler for intermediate code generation:

(I) Backpatching can be used to generate code for Boolean expression in one pass.
(II) Backpatching can be used to generate code for flow-of-control statements in one pass.

Which ONE of the following options is CORRECT?

Exam Year(s)

GATE CS - 2025,

Answer: C

Both (I) and (II) are correct.

Backpatching solves the problem of generating jumps whose targets are not yet known. The compiler emits a jump with its target left blank, records the instruction in a list (such as truelist, falselist or nextlist), and fills in the target later, once the label is known.

This lets a one-pass translator generate short-circuit code for Boolean expressions, where 'true' and 'false' exits jump forward to code not yet generated (I). It equally handles flow-of-control statements such as if, if-else and while, whose exit and loop-back jumps are patched when the statement ends (II). The classic textbook treatment (Aho, Sethi and Ullman) uses it for both.

Please log in or register to report this question.

4.

Consider an array A of n elements of integer type for assignment statement

Value = A[i]

Which of the following is three address code representation for address computation and value assignment above ?

Exam Year(s)

MH SET - 2019, SET Exam - 2019,

Answer: A

The correct three-address code is Temp1 = i * sizeof (integer), Temp2 = &A + Temp1, Value = *(Temp2).

The address of A[i] is the base address of A plus i times the size of one element. So the code first scales the index (Temp1 = i * sizeof(integer)), then adds it to the base address (Temp2 = &A + Temp1), and finally loads the value stored at that address (Value = *(Temp2)).

Option (B) uses Temp2 before it has been computed and stores into the array instead of reading from it. Options (C) and (D) multiply the base address itself, which has no meaning in address arithmetic: the base must be added, not scaled.

Please log in or register to report this question.

5.

Among the various ways an Intermediate code is represented, .................. intermediate code representation is close to the source program/language itself and ............. intermediate code representation is close to the target machine.

Exam Year(s)

MH SET - 2021, SET Exam - 2021,

Answer: C

The blanks are filled by High level, Low level.

Compilers use intermediate representations at different levels. A high-level representation, such as a syntax tree, keeps the structure of the source program (loops, array accesses, expressions), so it is close to the source language and suits machine-independent tasks such as type checking.

A low-level representation, such as three-address code close to machine instructions, is near the target machine and suits register allocation and instruction selection. The options that put low level first reverse the two, and 'medium level' is not the term used for the representation near the machine.

Please log in or register to report this question.

6.

A normalised heterogeneous abstract syntax tree must :

(i) Trees with magnitude of node type are called heterogeneous tree
(ii) Normalised heterogeneous tree use a normalised list of children like homogeneous tree
(iii) Nodes have irregular children
(iv) Use more than a single node data type but with normalised child list representation.

Exam Year(s)

MH SET - 2023, SET Exam - 2023,

Answer: A

The correct statements are (i), (ii) and (iv).

In the catalogue of AST patterns, trees with a multitude of node types (the paper's 'magnitude') are called heterogeneous trees (i). A normalised heterogeneous tree uses several node classes, but keeps the children in one normalised list, just as a homogeneous tree does (ii and iv).

Statement (iii), nodes with irregular children (each node class holding its children in its own named fields), describes the other variant, the irregular heterogeneous tree. So it does not belong to the normalised kind, and every option containing (iii) or missing (i), (ii) or (iv) is wrong.

Please log in or register to report this question.

7.

An...........is a data structure that is constructed from input data to a program and from which part or all of the output data of the program is constructed.

Exam Year(s)

MH SET - 2023, SET Exam - 2023,

Answer: C

It is an Intermediate Representation.

An intermediate representation is a data structure built by a program from its input, and from which part or all of its output is in turn produced. In a compiler, the front end builds an IR (an abstract syntax tree, three-address code and so on) from the source program, and the back end generates target code from it.

A symbol table records information about identifiers, a flow graph represents only the control flow, and an object file is the final output, not a structure between input and output.

Please log in or register to report this question.

Answer: C

One purpose is to increase the chances of reusing the machine-independent code optimizer in other compilers.

An intermediate representation separates the front end (source language) from the back end (target machine). Optimizations written on the intermediate code do not depend on either, so the same optimizer can be reused across compilers for different languages and machines.

Parsing and semantic analysis happen before intermediate code is produced, error reporting belongs to the front end, and register allocation is done for a specific machine in the back end, so the other options do not describe its purpose.

Please log in or register to report this question.

9.

Consider the following code segment :

x = u - t;
y = x * v;
x = y + w;
y = t - z;
y = x * y;

The minimum number of total variables required to convert the above code segment to static single assignment form is

Exam Year(s)

Tripura Public Service Commission - 2025,

Answer: D

The minimum number of variables is 10.

In static single assignment form every assignment creates a new variable:

\[ \begin{aligned} x_{1} &= u - t \\ y_{1} &= x_{1} \times v \\ x_{2} &= y_{1} + w \\ y_{2} &= t - z \\ y_{3} &= x_{2} \times y_{2} \end{aligned} \]

That gives five new variables (\(x_{1}, x_{2}, y_{1}, y_{2}, y_{3}\)) plus the five that are only read (u, t, v, w, z): 10 in all. 6, 8 and 9 reuse a name for two assignments or leave out some of the inputs.

Please log in or register to report this question.

10.

High - level intermediate language is

Exam Year(s)

Tripura Public Service Commission - 2019,

Answer: C

A high-level intermediate language is machine independent.

A compiler may use several intermediate representations. A high-level one, such as a syntax tree or three-address code, stays close to the source program and contains nothing about the registers or instructions of a particular processor, so the same front end can serve many targets. Low-level intermediate forms are the ones that become machine dependent.

FORTRAN (printed 'FORTAN') and COBOL are high-level programming languages, not intermediate languages.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Intermediate Code Generation Questions and Answers || Intermediate Code Generation MCQ Questions and Answers || Intermediate Code Generation GK Questions and Answers || Intermediate Code Generation GK MCQ Questions || Intermediate Code Generation Multiple Choice Questions and Answers || Intermediate Code Generation GK || GK on Intermediate Code Generation || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design