MauryaHub PYQ Practice

cs4032_2026T2_Q1_NA.pdf

Compiler Design · Quiz 1 · May 2026

← Course papers · Start practice / exam

Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.

Question 2 MCQ · 2.0 marks

Consider the following compiler phases and compiler tasks. [[IMAGE:e961af1b93d25766_2_2]] Which one of the following correctly matches the compiler phases with their primary tasks?
Source diagram or notation
  1. P-4, Q-3, R-2, S-1
  2. P-3, Q-4, R-2, S-1
  3. P-4, Q-1, R-2, S-3
  4. P-2, Q-3, R-4, S-1

A published solution is not available for this question yet.

Question 3 MCQ · 2.0 marks

Which of the following describes a key programmatic difference between the functionality of an Interpreter and a Compiler toolchain?
  1. Compilers execute code step-by-step at runtime, whereas interpreters translate the entire source program before execution.
  2. Interpreters can provide immediate statement-level runtime feedback.
  3. The machine-language target program produced by a compiler is typically 10 to 100 times slower than interpreter execution.
  4. Compilers completely eliminate the need for a runtime environment or stack frame allocation.

A published solution is not available for this question yet.

Question 4 MCQ · 2.0 marks

A compiler detects that the variable [[IMAGE:e961af1b93d25766_3_3]] is used before it is declared in a program. Which compiler phase is primarily responsible for reporting this error?
Source diagram or notation
  1. Lexical Analysis
  2. Syntax Analysis
  3. Code Generation
  4. Semantic Analysis

A published solution is not available for this question yet.

Question 5 MCQ · 2.0 marks

A C program contains a function-like macro [[IMAGE:e961af1b93d25766_3_4]] . During a code audit, a developer encounters the statement [[IMAGE:e961af1b93d25766_3_5]] . Which of the following statements correctly evaluates how the preprocessor handles this, and what the final value of [[IMAGE:e961af1b93d25766_3_6]] will be after execution?
Source diagram or notationSource diagram or notationSource diagram or notation
  1. The preprocessor checks the type, expands it to [[IMAGE:e961af1b93d25766_3_7]] , and evaluates to 25.
    Source diagram or notation
  2. The preprocessor textually replaces it to [[IMAGE:e961af1b93d25766_3_8]] , and it evaluates to 11.
    Source diagram or notation
  3. The preprocessor textually replaces it to [[IMAGE:e961af1b93d25766_3_9]] , and it evaluates to 17 due to left-to-right associativity.
    Source diagram or notation
  4. The compiler driver generates a syntax error because macro parameters require explicit parentheses.

A published solution is not available for this question yet.

Question 6 MCQ · 2.0 marks

A compiler architecture uses a common Intermediate Representation (IR). Initially, it supports **6** **source languages** and **4 target architectures**. Later, support for **3 new source languages** and **2 new target architectures** is added. Without using IR, the compiler requires one translator for every source-target pair. With IR, how many fewer translators/components are required after the expansion?
  1. 24
  2. 30
  3. 39
  4. 48

A published solution is not available for this question yet.

Question 7 MCQ · 2.0 marks

Which of the following is **NOT** a responsibility of the lexical analyzer?
  1. Removing white spaces and comments
  2. Recognizing keywords and identifiers
  3. Checking whether parentheses are properly balanced
  4. Producing tokens for the parser

A published solution is not available for this question yet.

Question 8 MCQ · 2.0 marks

A lexical analyzer processes the following input. [[IMAGE:e961af1b93d25766_4_10]] The token specifications are listed in this order. [[IMAGE:e961af1b93d25766_5_11]] The lexer follows both the **Longest Match Rule** and the **Earlier Matching Rule**. Which token sequence is generated?
Source diagram or notationSource diagram or notation
  1. [[IMAGE:e961af1b93d25766_5_12]]
    Source diagram or notation
  2. [[IMAGE:e961af1b93d25766_5_13]]
    Source diagram or notation
  3. [[IMAGE:e961af1b93d25766_5_14]]
    Source diagram or notation
  4. [[IMAGE:e961af1b93d25766_5_15]]
    Source diagram or notation

A published solution is not available for this question yet.

Question 9 MCQ · 2.0 marks

Consider the regular expression [[IMAGE:e961af1b93d25766_5_16]] Which of the following best describes the language of [[IMAGE:e961af1b93d25766_5_17]] ?
Source diagram or notationSource diagram or notation
  1. All strings with at most one **b**
  2. All strings where no two **b**'s are adjacent
  3. All strings ending in **a**
  4. All strings with an equal number of **a**'s and **b**'s

A published solution is not available for this question yet.

Question 10 MCQ · 2.0 marks

A programmer writes a Lex specification in a file named [[IMAGE:e961af1b93d25766_6_18]] . Which of the following correctly describes the sequence of steps required to obtain an executable lexical analyzer?
Source diagram or notation
  1. [[IMAGE:e961af1b93d25766_6_19]] → C compiler → executable
    Source diagram or notation
  2. [[IMAGE:e961af1b93d25766_6_20]] → Lex compiler → [[IMAGE:e961af1b93d25766_6_21]] → C compiler → executable
    Source diagram or notationSource diagram or notation
  3. [[IMAGE:e961af1b93d25766_6_22]] → Parser generator → executable
    Source diagram or notation
  4. [[IMAGE:e961af1b93d25766_6_23]] → Assembler → executable
    Source diagram or notation

A published solution is not available for this question yet.

Question 11 MSQ · 2.0 marks

Which of the following statements correctly describes **machine-independent optimizations**?
  1. They can be performed before generating target machine code.
  2. They depend on the instruction set of the target processor.
  3. Constant Folding is an example of machine-independent optimization.
  4. Copy Propagation is an example of machine-independent optimization.

A published solution is not available for this question yet.

Question 12 NAT · 3.0 marks

Consider the following declarations: [[IMAGE:e961af1b93d25766_7_24]] The compiler generates Three-Address Code (TAC) for the statement [[IMAGE:e961af1b93d25766_7_25]] Assume the following: • Integer arithmetic is performed whenever all operands are integers. • If an arithmetic operation involves both [[IMAGE:e961af1b93d25766_7_26]] and [[IMAGE:e961af1b93d25766_7_27]] , all operands are first converted to [[IMAGE:e961af1b93d25766_7_28]] . • [[IMAGE:e961af1b93d25766_7_29]] converts an [[IMAGE:e961af1b93d25766_7_30]] to a [[IMAGE:e961af1b93d25766_7_31]] . • [[IMAGE:e961af1b93d25766_7_32]] converts a [[IMAGE:e961af1b93d25766_7_33]] to an [[IMAGE:e961af1b93d25766_7_34]] . • The compiler generates the **minimum number of explicit type-conversion instructions**. Ignoring all arithmetic and assignment instructions, how many **explicit type-conversion** **instructions** are required?
Source diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notation

    A published solution is not available for this question yet.

    Question 13 MCQ · 4.0 marks

    A compiler generates the following Three-Address Code (TAC) to compute the **final bill amount** after adding a fixed service charge to the item price. The compiler then applies the following optimizations in order: 1. Constant Folding 2. Copy Propagation 3. Dead Code Elimination [[IMAGE:e961af1b93d25766_8_35]] Which of the following is the optimized TAC?
    Source diagram or notation
    1. [[IMAGE:e961af1b93d25766_8_36]]
      Source diagram or notation
    2. [[IMAGE:e961af1b93d25766_8_37]]
      Source diagram or notation
    3. [[IMAGE:e961af1b93d25766_8_38]]
      Source diagram or notation
    4. [[IMAGE:e961af1b93d25766_9_39]]
      Source diagram or notation

    A published solution is not available for this question yet.

    Question 14 MCQ · 4.0 marks

    [[IMAGE:e961af1b93d25766_9_40]]
    Source diagram or notation
    1. [[IMAGE:e961af1b93d25766_9_41]] , [[IMAGE:e961af1b93d25766_9_42]] , [[IMAGE:e961af1b93d25766_9_43]] , [[IMAGE:e961af1b93d25766_9_44]] , [[IMAGE:e961af1b93d25766_9_45]]
      Source diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notation
    2. [[IMAGE:e961af1b93d25766_9_46]] , [[IMAGE:e961af1b93d25766_9_47]] , [[IMAGE:e961af1b93d25766_9_48]] , [[IMAGE:e961af1b93d25766_9_49]] , [[IMAGE:e961af1b93d25766_9_50]] , [[IMAGE:e961af1b93d25766_9_51]]
      Source diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notation
    3. [[IMAGE:e961af1b93d25766_9_52]] , [[IMAGE:e961af1b93d25766_9_53]] , [[IMAGE:e961af1b93d25766_9_54]] , [[IMAGE:e961af1b93d25766_9_55]] , [[IMAGE:e961af1b93d25766_9_56]] , [[IMAGE:e961af1b93d25766_9_57]] , [[IMAGE:e961af1b93d25766_9_58]]
      Source diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notation
    4. [[IMAGE:e961af1b93d25766_10_59]] , [[IMAGE:e961af1b93d25766_10_60]] , [[IMAGE:e961af1b93d25766_10_61]] , [[IMAGE:e961af1b93d25766_10_62]] , [[IMAGE:e961af1b93d25766_10_63]]
      Source diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notation

    A published solution is not available for this question yet.

    Question 15 MCQ · 3.0 marks

    A compiler generates the following **Abstract Syntax Tree (AST)** for an expression. [[IMAGE:e961af1b93d25766_10_64]] Which of the following **Three-Address Code (TAC)** sequences correctly represents the AST?
    Source diagram or notation
    1. [[IMAGE:e961af1b93d25766_10_65]]
      Source diagram or notation
    2. [[IMAGE:e961af1b93d25766_10_66]]
      Source diagram or notation
    3. [[IMAGE:e961af1b93d25766_10_67]]
      Source diagram or notation
    4. [[IMAGE:e961af1b93d25766_11_68]]
      Source diagram or notation

    A published solution is not available for this question yet.

    Question 16 MCQ · 3.0 marks

    A compiler performs lexical analysis and stores: • every **unique identifier** in the **Symbol Table**, • every **unique integer constant** in the **Constant Table**. Keywords, operators, delimiters, and punctuation symbols are **not** stored in either table. Consider the following program. [[IMAGE:e961af1b93d25766_11_69]] How many entries will be present in the **Symbol Table** and the **Constant Table**, respectively?
    Source diagram or notation
    1. Symbol Table = **5**, Constant Table = **3**
    2. Symbol Table = **4**, Constant Table = **2**
    3. Symbol Table = **5**, Constant Table = **2**
    4. Symbol Table = **6**, Constant Table = **2**

    A published solution is not available for this question yet.

    Question 17 MCQ · 3.0 marks

    Consider the following **Deterministic Finite Automaton (DFA)** [[IMAGE:e961af1b93d25766_11_70]] , where: • [[IMAGE:e961af1b93d25766_11_71]] • [[IMAGE:e961af1b93d25766_12_72]] • Start state: [[IMAGE:e961af1b93d25766_12_73]] • Final states: [[IMAGE:e961af1b93d25766_12_74]] The transition diagram is given below [[IMAGE:e961af1b93d25766_12_75]] Assume that any **undefined transition leads to a dead (trap) state**, which is not shown in the table. Which of the following regular expressions describes the language accepted by the DFA?
    Source diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notation
    1. [[IMAGE:e961af1b93d25766_12_76]]
      Source diagram or notation
    2. [[IMAGE:e961af1b93d25766_12_77]]
      Source diagram or notation
    3. [[IMAGE:e961af1b93d25766_12_78]]
      Source diagram or notation
    4. [[IMAGE:e961af1b93d25766_12_79]]
      Source diagram or notation

    A published solution is not available for this question yet.

    Question 18 NAT · 4.0 marks

    A compiler back-end generates the following Three-Address Code (TAC) for an **image** **enhancement** algorithm. [[IMAGE:e961af1b93d25766_13_80]] Assume that: • [[IMAGE:e961af1b93d25766_13_81]] , [[IMAGE:e961af1b93d25766_13_82]] , [[IMAGE:e961af1b93d25766_13_83]] , [[IMAGE:e961af1b93d25766_13_84]] , [[IMAGE:e961af1b93d25766_13_85]] , [[IMAGE:e961af1b93d25766_13_86]] , [[IMAGE:e961af1b93d25766_13_87]] , [[IMAGE:e961af1b93d25766_13_88]] , and [[IMAGE:e961af1b93d25766_13_89]] are read directly from memory. • Only the compiler-generated temporaries ( [[IMAGE:e961af1b93d25766_13_90]] – [[IMAGE:e961af1b93d25766_13_91]] ) occupy hardware registers. • A temporary remains **live** from the instruction where it is defined until its **last use**. • Instructions are executed strictly in the given order. What is the **maximum number of compiler-generated temporaries that are simultaneously** **live** during the execution of the above TAC?
    Source diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notation

      A published solution is not available for this question yet.

      Question 19 MSQ · 3.0 marks

      Consider the following **Deterministic Finite Automaton (DFA)** [[IMAGE:e961af1b93d25766_14_92]] where • [[IMAGE:e961af1b93d25766_14_93]] • [[IMAGE:e961af1b93d25766_14_94]] • Start state: [[IMAGE:e961af1b93d25766_14_95]] • Accepting states: [[IMAGE:e961af1b93d25766_14_96]] The transition function [[IMAGE:e961af1b93d25766_14_97]] is given below. [[IMAGE:e961af1b93d25766_14_98]] Which of the following strings are accepted by the DFA?
      Source diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notationSource diagram or notation
      1. 10111
      2. 1010
      3. 0100
      4. 100001
      5. 0001

      A published solution is not available for this question yet.

      Question 20 MSQ · 3.0 marks

      Consider the following statements about **Deterministic Finite Automata (DFA)** and **Nondeterministic Finite Automata (NFA)**. Which of the following statement(s) is/are **correct**?
      1. There exist languages that can be accepted by an NFA but not by any DFA.
      2. An NFA accepts an input string if at least one computation path reaches an accepting state after reading the entire input.
      3. A DFA has exactly one transition for every input symbol from each state.
      4. An NFA accepts an input string only if all possible computation paths end in accepting states.
      5. Every language accepted by an NFA can also be accepted by a DFA.

      A published solution is not available for this question yet.