1.
The address code involves
Correct Answer
B. At most Three address
Explanation
The given answer suggests that the address code may involve up to three addresses, but it does not necessarily have to use all three. This means that the code can have one, two, or three addresses, but not more than three. Additionally, the answer states that there are no unary operators involved in the address code.
2.
An intermediate code form is
Correct Answer
D. All of the mentioned
Explanation
The correct answer is "All of the mentioned" because an intermediate code form can be represented in various ways, including post-fix notation, syntax trees, and three address code. All of these forms are commonly used in compilers and programming languages to represent the intermediate code generated during the compilation process. Therefore, all the options mentioned are valid representations of intermediate code.
3.
The graph that shows basic blocks and their successor relationship is called
Correct Answer
B. Flow GrapH
Explanation
A flow graph is a graph that represents the control flow of a program by showing the basic blocks and their successor relationships. Each basic block represents a sequence of instructions that are executed together. The successor relationships indicate the order in which the basic blocks are executed. Therefore, a flow graph is the correct term to describe the graph that shows basic blocks and their successor relationship.
4.
Some code optimizations are carried out on the intermediate code because
Correct Answer
A. They enhance the portability of the compiler to other target processors
Explanation
The reason why some code optimizations are carried out on the intermediate code is because it enhances the portability of the compiler to other target processors. By optimizing the intermediate code, the compiler can generate efficient machine code that can be executed on different processors without the need for extensive modifications. This allows the compiler to be more versatile and adaptable to different hardware architectures, making it easier to port the compiler to different platforms.
5.
Consider the following C code segment.
for (i = 0, i
{
for (j=0; j
{
if (i%2)
{
x += (4*j + 5*i);
y += (7 + 4*j);
}}
}
Which one of the following is false?
Correct Answer
D. There is scope of dead code elimination in this code
Explanation
The given code segment does not contain any dead code, which means that all the code within the loops is necessary for the program's functionality. Therefore, there is no scope for dead code elimination in this code.
6.
Consider the intermediate code given below:
1. i = 1
2. j = 1
3. t1 = 5 * i
4. t2 = t1 + j
5. t3 = 4 * t2
6. t4 = t3
7. a[t4] = –1
8. j = j + 1
9. if j <= 5 goto(3)
10. i = i + 1
11. if i < 5 goto(2)
The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are
Correct Answer
B. 6 and 7
Explanation
The given intermediate code represents a loop structure where the statements inside the loop are executed multiple times until the condition is met. The control-flow-graph is a graphical representation of the flow of control in the code. In this case, there are two loops, one nested inside the other. Each loop contributes one node to the control-flow-graph. Additionally, there are other statements outside the loops that contribute to the nodes as well. Therefore, the total number of nodes is 6. The edges in the control-flow-graph represent the flow of control between different nodes. Since there are multiple branches and loops in the code, there are a total of 7 edges in the control-flow-graph.
7.
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
Correct Answer
D. 10
8.
Consider the following source code :
c = a + b
d = c
c = c – e
a = d – e
b = b * e
b = d/b
Which of the following is correct optimization of given code?
Correct Answer
B.
c = a + b
d = c
c = c – e
a = d – e
b = d/b
Explanation
The correct optimization of the given code is the third option. This is because it minimizes the number of operations and unnecessary assignments. By assigning c = a + b first, we can reuse the value of c in the subsequent calculations. Then, we assign d = c to store the value of c before it is updated. Next, we update c by subtracting e from it. After that, we update a by subtracting e from d. Finally, we update b by multiplying it with e and then dividing d by b. This optimization reduces the number of redundant calculations and assignments.
9.
Peephole optimization is form of
Correct Answer
A. Loop optimization
Explanation
Loop optimization is the correct answer because peephole optimization is a specific type of optimization technique that focuses on improving the efficiency of code within loops. It analyzes and modifies code at a small scale, typically within a fixed window of instructions known as a "peephole." This technique aims to eliminate redundant or unnecessary instructions, rearrange code for better performance, and optimize loop structures. Therefore, loop optimization is the most appropriate category for peephole optimization.
10.
In compiler terminology reduction in strength means
Correct Answer
D. Replacing a costly operation by a relatively cheaper one
Explanation
Reduction in strength in compiler terminology refers to the process of replacing a costly operation with a relatively cheaper one. This optimization technique aims to improve the efficiency of the compiled code by replacing expensive computations with less expensive alternatives. By doing so, the overall performance of the program can be enhanced, as the execution time is reduced. This technique is particularly useful in situations where the same result can be achieved using a less resource-intensive operation.
11.
Substitution of values for names (whose values are constants) is done in
Correct Answer
C. Constant folding
Explanation
Constant folding is the process of evaluating constant expressions at compile time instead of runtime. In this process, values for names that are constants are substituted with their actual values. This optimization technique helps in reducing the number of instructions and improving the efficiency of the program. Therefore, the substitution of values for names (whose values are constants) is done in constant folding.
12.
The method which merges the bodies of two loops is
Correct Answer
B. Loop Jamming
Explanation
Loop jamming is the method that merges the bodies of two loops. It involves combining the code of two separate loops into a single loop, thereby reducing the number of iterations and improving efficiency. This technique is commonly used in loop optimization to eliminate redundant code and improve the performance of the program. Constant folding, loop rolling, and none of these do not involve merging loop bodies, making them incorrect choices.
13.
Syntax directed translation scheme is desirable because
Correct Answer
C. It is easy to modify
Explanation
A syntax directed translation scheme is desirable because it is easy to modify. This means that if there are any changes or updates needed in the translation scheme, it can be easily done without affecting the overall implementation or description. This flexibility allows for efficient and hassle-free modifications, making the syntax directed translation scheme a desirable choice.
14.
The optimization technique which is typically applied on loops is
Correct Answer
D. All of these
Explanation
The optimization technique that is typically applied on loops is known as "All of these." This means that all of the mentioned techniques (removal of invariant computation, peephole optimization, and constant folding) are commonly used to optimize loops. These techniques aim to improve the efficiency and performance of loops by eliminating redundant computations, optimizing code at a small scale, and evaluating constant expressions during compilation.
15.
The graph that shows basic blocks and their successor relationship is called
Correct Answer
B. Flow grapH
Explanation
A flow graph is a graphical representation of a program's control flow, where each basic block represents a sequence of instructions and the edges represent the flow of control between these blocks. It shows the successor relationship between the basic blocks, indicating the order in which they are executed. Therefore, a flow graph is the correct term for the graph that shows basic blocks and their successor relationship.
16.
An intermediate code form is
Correct Answer
D. All of these
Explanation
The correct answer is "All of these" because an intermediate code form can be represented in postfix notation, syntax trees, and three address code. Postfix notation is a way of representing mathematical expressions where the operators are placed after their operands. Syntax trees are graphical representations of the structure of a program's source code. Three address code is a low-level programming language that uses three operands per instruction. Therefore, all of these options are valid intermediate code forms.
17.
Input to code generator
Correct Answer
B. Intermediate code
Explanation
The given options are different stages in the process of code generation. The source code is the original code written by the programmer, the target code is the final code that is executed by the computer, and the intermediate code is an intermediate representation of the code that is used in the compilation process. Out of these options, the intermediate code is the most suitable answer as it represents a stage in the code generation process.
18.
The identification of common sub-expression and replacement of run-time computations by compile-time computations is
Correct Answer
C. Constant folding
Explanation
Constant folding is the process of simplifying expressions at compile-time by evaluating them to a constant value. This optimization technique is used to identify common sub-expressions and replace them with their computed values, reducing the need for runtime computations. By performing constant folding, the compiler can optimize the code by eliminating redundant calculations and improving the overall efficiency of the program. Therefore, constant folding is the correct answer in this context.
19.
Local and loop optimization in turn provide motivation for
Correct Answer
A. Data flow analysis
Explanation
Local and loop optimization are techniques used to improve the efficiency of code by optimizing specific sections or loops. These optimizations can identify redundant operations, eliminate unnecessary computations, and improve memory access patterns. Data flow analysis is a technique that analyzes how data is used and propagated throughout the program. It can identify dependencies and determine the optimal ordering of operations. Therefore, data flow analysis is motivated by local and loop optimization as it provides valuable insights into the data dependencies and allows for further optimization opportunities. Constant folding and peephole optimization are also optimization techniques, but they are not directly related to the motivation behind data flow analysis.
20.
An optimizing compiler
Correct Answer
D. All of the above
Explanation
An optimizing compiler is designed to improve the performance of the compiled code by making it occupy less space, take less time for execution, and optimize the code itself. This means that it aims to reduce the memory footprint of the compiled program, make it run faster, and optimize the code structure and logic to enhance efficiency. Therefore, all of the given options accurately describe the purpose and capabilities of an optimizing compiler.
21.
A basic block can be analyzed by
Correct Answer
A. DAG
Explanation
A basic block can be analyzed by a DAG (Directed Acyclic Graph) because a DAG represents the dependencies and relationships between the instructions in the basic block without any cycles. This allows for efficient analysis and optimization of the basic block's instructions. A flow graph and a graph with cycles may not accurately represent the dependencies and relationships within a basic block, making them less suitable for analysis. Therefore, the correct answer is DAG.
22.
A pictorial representation of the value computed by each statement in the basic block is
Correct Answer
B. DAG
Explanation
The correct answer is DAG. A Directed Acyclic Graph (DAG) is a pictorial representation that can be used to represent the value computed by each statement in a basic block. It is a graph that consists of nodes representing statements and edges representing dependencies between the statements. The DAG is acyclic, meaning there are no cycles or loops in the graph. This representation is commonly used in compiler optimization techniques to analyze and optimize code.
23.
Boolean expressions have following purposes
Correct Answer
C. Both a &b
Explanation
Boolean expressions have two main purposes: computing logical values and being used as conditional expressions. "Computing logical values" means that boolean expressions can evaluate to either true or false based on the values of the variables involved. "Used as conditional expressions" means that boolean expressions can be used to determine whether a certain condition is true or false, and based on that, execute different parts of a program. Therefore, the correct answer is "both a & b" because boolean expressions serve both of these purposes.
24.
__________can be used to generate code for Boolean expressions and flow of-control statements in one pass.
Correct Answer
A. Backpatching
Explanation
Backpatching is a technique used in code generation where temporary placeholders, called "backpatching points," are inserted into the code. These placeholders are later filled with the actual addresses or labels during a second pass. This allows the code generator to handle Boolean expressions and flow-of-control statements in a single pass, as it can defer the resolution of addresses or labels until all necessary information is available. This technique improves efficiency and simplifies the code generation process.
25.
Principal methods of representing the value of boolean expression
Correct Answer
D. All of the above
Explanation
The correct answer is "all of the above" because all three methods mentioned - encoding true & false numerically, evaluating boolean expression analogously to an arithmetic expression, and implementing boolean expression by flow of control - are valid and commonly used ways of representing the value of boolean expressions. Each method has its own advantages and is suitable for different scenarios. Therefore, the correct answer is that all of these methods can be used to represent the value of boolean expressions.
26.
Quadruple is a record structure with four fields
Correct Answer
A. Op, arg1, arg2 and result
Explanation
The correct answer is "Op, arg1, arg2 and result". This is because the question is asking for the fields that are present in a Quadruple record structure. The given options include different combinations of fields, but only the option "Op, arg1, arg2 and result" includes all four fields mentioned in the question. Therefore, this is the correct answer.
27.
Listing pointers to triples, rather than listing triples themselves is implementation of
Correct Answer
C. Indirect Triple
Explanation
Indirect Triple is an implementation technique where instead of directly listing the triples themselves, pointers to the triples are listed. This approach helps in reducing the memory space required to store the triples and improves the efficiency of the implementation. By using pointers, we can easily access and manipulate the triples when needed. This technique is commonly used in compiler design and optimization.
28.
A parse tree showing the value of attributes at each node
Correct Answer
A. Annotated parse tree
Explanation
An annotated parse tree is a parse tree that includes additional information or attributes at each node. This additional information can represent the value of attributes associated with each node, such as type information or semantic meaning. Therefore, an annotated parse tree can be considered as a type of parse tree that shows the value of attributes at each node.
29.
The size field of activation record can be determined at
Correct Answer
C. Both a) and b)
Explanation
The size field of an activation record, which contains information about the variables and parameters of a function, can be determined at both runtime and compile time. At compile time, the compiler can analyze the code and calculate the size of the activation record based on the variables and their types. At runtime, if the code includes dynamic memory allocation or variable-length arrays, the size of the activation record may need to be determined dynamically. Therefore, the size field of an activation record can be determined at both compile time and runtime.
30.
In activation tree each node represent
Correct Answer
B. Activation of a procedure
Explanation
The correct answer is "activation of a procedure". In an activation tree, each node represents the activation of a procedure. This means that each node represents the execution of a specific procedure within the main program. The activation of a procedure includes the allocation of memory for local variables, the execution of the procedure's code, and the management of the procedure's return value. Therefore, the activation tree provides a visual representation of the flow of control and the hierarchy of procedure invocations within a program.