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?

P-4, Q-3, R-2, S-1
P-3, Q-4, R-2, S-1
P-4, Q-1, R-2, S-3
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?
Compilers execute code step-by-step at runtime, whereas interpreters
translate the entire source program before execution.
Interpreters can provide immediate statement-level runtime feedback.
The machine-language target program produced by a compiler is typically 10
to 100 times slower than interpreter execution.
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?

Lexical Analysis
Syntax Analysis
Code Generation
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?



The preprocessor checks the type, expands it to [[IMAGE:e961af1b93d25766_3_7]] , and
evaluates to 25.

The preprocessor textually replaces it to [[IMAGE:e961af1b93d25766_3_8]] , and it evaluates to
11.

The preprocessor textually replaces it to [[IMAGE:e961af1b93d25766_3_9]] , and it evaluates to
17 due to left-to-right associativity.

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?
24
30
39
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?
Removing white spaces and comments
Recognizing keywords and identifiers
Checking whether parentheses are properly balanced
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?


[[IMAGE:e961af1b93d25766_5_12]]

[[IMAGE:e961af1b93d25766_5_13]]

[[IMAGE:e961af1b93d25766_5_14]]

[[IMAGE:e961af1b93d25766_5_15]]

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


All strings with at most one **b**
All strings where no two **b**'s are adjacent
All strings ending in **a**
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?

[[IMAGE:e961af1b93d25766_6_19]] → C compiler → executable

[[IMAGE:e961af1b93d25766_6_20]] → Lex compiler → [[IMAGE:e961af1b93d25766_6_21]] → C compiler → executable


[[IMAGE:e961af1b93d25766_6_22]] → Parser generator → executable

[[IMAGE:e961af1b93d25766_6_23]] → Assembler → executable

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**?
They can be performed before generating target machine code.
They depend on the instruction set of the target processor.
Constant Folding is an example of machine-independent optimization.
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?











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?

[[IMAGE:e961af1b93d25766_8_36]]

[[IMAGE:e961af1b93d25766_8_37]]

[[IMAGE:e961af1b93d25766_8_38]]

[[IMAGE:e961af1b93d25766_9_39]]

A published solution is not available for this question yet.
Question 14 MCQ · 4.0 marks
[[IMAGE:e961af1b93d25766_9_40]]

[[IMAGE:e961af1b93d25766_9_41]] , [[IMAGE:e961af1b93d25766_9_42]] , [[IMAGE:e961af1b93d25766_9_43]] ,
[[IMAGE:e961af1b93d25766_9_44]] , [[IMAGE:e961af1b93d25766_9_45]]





[[IMAGE:e961af1b93d25766_9_46]] , [[IMAGE:e961af1b93d25766_9_47]] , [[IMAGE:e961af1b93d25766_9_48]] ,
[[IMAGE:e961af1b93d25766_9_49]] , [[IMAGE:e961af1b93d25766_9_50]] , [[IMAGE:e961af1b93d25766_9_51]]






[[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]]







[[IMAGE:e961af1b93d25766_10_59]] , [[IMAGE:e961af1b93d25766_10_60]] , [[IMAGE:e961af1b93d25766_10_61]] , [[IMAGE:e961af1b93d25766_10_62]] ,
[[IMAGE:e961af1b93d25766_10_63]]





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?

[[IMAGE:e961af1b93d25766_10_65]]

[[IMAGE:e961af1b93d25766_10_66]]

[[IMAGE:e961af1b93d25766_10_67]]

[[IMAGE:e961af1b93d25766_11_68]]

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?

Symbol Table = **5**, Constant Table = **3**
Symbol Table = **4**, Constant Table = **2**
Symbol Table = **5**, Constant Table = **2**
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?






[[IMAGE:e961af1b93d25766_12_76]]

[[IMAGE:e961af1b93d25766_12_77]]

[[IMAGE:e961af1b93d25766_12_78]]

[[IMAGE:e961af1b93d25766_12_79]]

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?












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?







10111
1010
0100
100001
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**?
There exist languages that can be accepted by an NFA but not by any DFA.
An NFA accepts an input string if at least one computation path reaches an
accepting state after reading the entire input.
A DFA has exactly one transition for every input symbol from each state.
An NFA accepts an input string only if all possible computation paths end in
accepting states.
Every language accepted by an NFA can also be accepted by a DFA.
A published solution is not available for this question yet.