Compiler Quiz 2 (III Cse C)

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Sruthi M
S
Sruthi M
Community Contributor
Quizzes Created: 1 | Total Attempts: 247
Questions: 30 | Attempts: 247

SettingsSettingsSettings
Compiler Quiz 2 (III Cse C) - Quiz


Questions and Answers
  • 1. 

    The address code involves

    • A.

      Exactly 3 address

    • B.

      At most Three address

    • C.

      No unary operators

    • D.

      None of the mentioned

    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.

    Rate this question:

  • 2. 

    An intermediate code form is

    • A.

      Post-fix Notation

    • B.

      Syntax Trees

    • C.

      Three address code

    • D.

      All of the mentioned

    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.

    Rate this question:

  • 3. 

    The graph that shows basic blocks and their successor relationship is called

    • A.

      Dag

    • B.

      Flow Graph

    • C.

      Control Graph

    • D.

      Hamilton Graph

    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.

    Rate this question:

  • 4. 

    Some code optimizations are carried out on the intermediate code because

    • A.

      They enhance the portability of the compiler to other target processors  

    • B.

      Program analysis is more accurate on intermediate code than on machine code

    • C.

      The information from dataflow analysis cannot otherwise be used for optimization

    • D.

      The information from the front end cannot otherwise be used for optimization

    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.

    Rate this question:

  • 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?

    • A.

      The code contains loop invariant computation

    • B.

      There is scope of common sub-expression elimination in this code

    • C.

      There is scope of strength reduction in this code

    • D.

      There is scope of dead code elimination in this code

    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.

    Rate this question:

  • 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

    • A.

      5 and 7

    • B.

      6 and 7

    • C.

      5 and 5

    • D.

      7 and 8

    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.

    Rate this question:

  • 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 

    • A.

      6

    • B.

      8

    • C.

      9

    • D.

      10

    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?

    • A.

      c = a + b    t = b * e    a = d – e    b = d/t    c = a

    • B.

      c = a + b       d = c       c = c – e       a = d – e       b = d/b

    • C.

      d = c      c = c – e      a = d – e      b = b * e      b = d/b

    • D.

      None of the above

    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.

    Rate this question:

  • 9. 

    Peephole optimization is form of

    • A.

      Loop optimization

    • B.

      Local optimization

    • C.

      Constant folding

    • D.

      Data flow analysis

    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.

    Rate this question:

  • 10. 

    In compiler terminology reduction in strength means

    • A.

      Replacing run time computation by compile time computation

    • B.

      Removing common subexpression

    • C.

      Removing loop invariant computation

    • D.

      Replacing a costly operation by a relatively cheaper one

    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.

    Rate this question:

  • 11. 

    Substitution of values for names (whose values are constants) is done in

    • A.

      Local optimization

    • B.

      Loop optimization

    • C.

      Constant folding

    • D.

      Strength reduction

    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.

    Rate this question:

  • 12. 

    The method which merges the bodies of two loops is

    • A.

      Loop rolling

    • B.

      Loop Jamming

    • C.

      Constant folding

    • D.

      None of these

    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.

    Rate this question:

  • 13. 

    Syntax directed translation scheme is desirable because

    • A.

      It is based on the syntax

    • B.

      Its description is independent of any implementation

    • C.

      It is easy to modify  

    • D.

      All of these

    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.

    Rate this question:

  • 14. 

    The optimization technique which is typically applied on loops is

    • A.

      Removal of invariant computation

    • B.

      Peephole optimization

    • C.

      Constant folding

    • D.

      All of these

    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.

    Rate this question:

  • 15. 

    The graph that shows basic blocks and their successor relationship is called

    • A.

      DAG

    • B.

      Flow graph

    • C.

      Control graph

    • D.

      Hamiltonian graph

    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.

    Rate this question:

  • 16. 

    An intermediate code form is

    • A.

      Postfix notation

    • B.

      Syntax trees

    • C.

      Three address code

    • D.

      All of these

    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.

    Rate this question:

  • 17. 

    Input to code generator

    • A.

      Source code

    • B.

      Intermediate code

    • C.

      Target code

    • D.

      All of the above

    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.

    Rate this question:

  • 18. 

    The identification of common sub-expression and replacement of run-time computations by compile-time computations is

    • A.

      Local optimization

    • B.

      Loop optimization

    • C.

      Constant folding

    • D.

      Data flow analysis

    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.

    Rate this question:

  • 19. 

    Local and loop optimization in turn provide motivation for

    • A.

      Data flow analysis

    • B.

      Constant folding

    • C.

      Peep hole optimization

    • D.

      DFA and constant folding

    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.

    Rate this question:

  • 20. 

    An optimizing compiler

    • A.

      Is optimized to occupy less space

    • B.

      Is optimized to take less time for execution

    • C.

      Optimizes the code

    • D.

      All of the above

    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.

    Rate this question:

  • 21. 

    A basic block can be analyzed by

    • A.

      DAG

    • B.

      A flow graph

    • C.

      A graph with cycles

    • D.

      None of the above

    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.

    Rate this question:

  • 22. 

    A pictorial representation of the value computed by each statement in the basic block is

    • A.

      Tree

    • B.

      DAG

    • C.

      Graph

    • D.

      None of the above

    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.

    Rate this question:

  • 23. 

    Boolean expressions have following purposes

    • A.

      Computing logical values

    • B.

      Used as conditional expressions

    • C.

      Both a &b

    • D.

      None of the above

    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.

    Rate this question:

  • 24. 

    __________can be used to generate code for Boolean expressions and flow of-control statements in one pass.

    • A.

      Backpatching

    • B.

      Code-generator

    • C.

      Parser

    • D.

      Static checker

    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.

    Rate this question:

  • 25. 

    Principal methods of representing the value of boolean expression

    • A.

      Encoding true & false numerically

    • B.

      To evaluate boolean expression analogously to an arithmetic expression

    • C.

      Implementing boolean expression by flow of control

    • D.

      All of the above

    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.

    Rate this question:

  • 26. 

    Quadruple is a record structure with four fields

    • A.

      Op, arg1, arg2 and result

    • B.

      Op1, op2, agr2 and result

    • C.

      Agr1, arg2 , result  and op

    • D.

      All of d above

    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.

    Rate this question:

  • 27. 

    Listing    pointers    to    triples,    rather    than    listing    triples    themselves    is   implementation of

    • A.

      Quadruple

    • B.

      Triple

    • C.

      Indirect Triple

    • D.

      Three address code

    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.

    Rate this question:

  • 28. 

    A parse tree showing the value of attributes at each node

    • A.

      Annotated parse tree

    • B.

      Syntax tree

    • C.

      Semantic tree

    • D.

      All of the above

    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.

    Rate this question:

  • 29. 

    The size field of activation record can be determined at

    • A.

      Run time

    • B.

      Compile time

    • C.

      Both a) and b)

    • D.

      None of the above

    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.

    Rate this question:

  • 30. 

    In activation tree each node represent

    • A.

      Activation of main program

    • B.

      Activation of a procedure

    • C.

      Both a and b

    • D.

      None of above

    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.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 14, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 12, 2019
    Quiz Created by
    Sruthi M
Back to Top Back to top
Advertisement