Compiler Design Week 1 NPTEL Assignment Answers 2026

1. Which phase of the compiler generates target machine code?

(A) Lexical Analysis
(B) Syntax Analysis
(C) Semantic Analysis
(D) Code Generation

Answer : See Answers

2. Which phase of a compiler checks syntax errors?

(A) Lexical Analysis
(B) Syntax Analysis
(C) Semantic Analysis
(D) Code Generation

Answer :

3. The number of tokens in the following C statement, printf(“%d”, 5 + 3 * 2); is

(A) 8
(B) 11
(C) 12
(D) 14

Answer :

4. During semantic analysis, which of the following checks are typically performed?

(A) Syntax errors like missing semicolons
(B) Type compatibility in expressions, undeclared identifiers, and function call arguments
(C) Register allocation for machine code
(D) Linking object modules

Answer :

5. The frontend of a compiler generates Intermediate Code (IC). This Intermediate Code can be executed on

(A) any machine
(B) only a specific machine
(C) only the compiler’s host machine
D) cannot be executed on any machine

Answer : See Answers

6. The main objective of code optimization in a compiler is to:

(A) Reduce program execution time
(B) Reduce memory usage
(C) Reduce both execution time and memory usage
(D) Reduce compilation time

Answer :

7. The symbol table in a compiler primarily stores:

(A) Identifier names and their types
(B) Identifier names, types, and memory locations
(C) Identifier names, types, memory locations, and scope information
(D) Only memory locations of identifiers

Answer :

8. Which of the following is a key difference between CISC and RISC architectures?

(A) CISC has more instructions than RISC
(B) RISC instructions are generally simpler than CISC instructions
(C) CISC instructions may take multiple cycles; RISC instructions usually take a single cycle
(D) All of the above

Answer :

9. Which of the following is not a part of the Syntax Analysis phase of a compiler?

(A) Parse Tree
(B) Context-Free Grammar
(C) Parsing
(D) Lexeme

Answer :

10. Which of the following is a part of Code Optimization in a compiler?

(A) Constant foldin
(B) Dead code eliminatio
(C) Strength reduction
(D) All of the above

Answer : See Answers

NPTEL Compiler Design Week 2 Assignment Answers 2025

1. Which of the following is a stage of the compilation process?
(A) Syntax analysis
(B) Intermediate code generation
(C) Code generation
(D) All of the mentioned
✔️Answer: D

📝 Explanation:
The compilation process consists of several phases including:

  • Syntax Analysis: Checks the grammar of code.
  • Intermediate Code Generation: Converts source code into an intermediate format.
  • Code Generation: Produces machine-level code.
    Hence, all of the mentioned stages are part of the compilation process.

2. A programmer writes instructions to multiply two numbers instead of adding them by mistake within a program. Which of the following is true in this context?
(A) Lexical analysis phase of compilation process can detect the error
(B) Syntax analysis phase of compilation process can detect the error
(C) In code generation phase the error can be detected
(D) This error cannot be detected by a compiler
✔️Answer: D

📝 Explanation:
This is a logical or semantic error, not a syntax or lexical one. The compiler assumes that you meant to multiply. So it can’t detect such logic mistakes.


3. Name the system program that is used to combine a program’s several compiled modules into a executable form:
(A) Interpreter
(B) Assembler
(C) Compiler
(D) Linking Loader
✔️Answer: D

📝 Explanation:
A linking loader links multiple object files and loads them into memory to create an executable. It resolves external references between modules.


4. The output of a lexical analyzer is:
(A) A parse tree
(B) Intermediate code
(C) A stream of tokens
(D) Machine code
✔️Answer: C

📝 Explanation:
The lexical analyzer breaks the source code into tokens like keywords, identifiers, operators, etc. These tokens are then sent to the syntax analyzer.


5. How many lexemes are there in the following code:

cCopyEditint main() { printf("%d + %d = %d", 3, 1, 4); return 0; }

(A) 18
(B) 20
(C) 22
(D) 24
✔️Answer: B

📝 Explanation:
Lexemes are the smallest units (like keywords, identifiers, constants, symbols).
Let’s count: int, main, (, ), {, printf, (, "...", ,, 3, ,, 1, ,, 4, ), ;, return, 0, ;, }20 lexemes


6. Which of the following is/are true for RISC architecture?
(A) Simplified instruction set leads to faster processing
(B) Execution in a pipeline is not possible
(C) Higher power consumption
(D) Has simple addressing modes
✔️Answer: A, D

📝 Explanation:
RISC (Reduced Instruction Set Computer) uses simple instructions that can be executed quickly.

  • Pipelining is actually possible and common in RISC.
  • Power consumption is usually lower.

7. Which particular task of compilation process uses context free grammars (CFG)?
(A) Code optimization
(B) Tokenization of input code
(C) Parsing of tokenized input
(D) None of the above
✔️Answer: C

📝 Explanation:
Parsing (syntax analysis) uses CFG to build the structure of the program and check grammar. CFG defines rules for syntactic structure.


8. Which of the following machine model is necessary and sufficient for designing lexical analyzer?
(A) Finite state automata
(B) Pushdown automata
(C) Turing machine
(D) None of the above
✔️Answer: A

📝 Explanation:
Lexical analyzers are based on Finite Automata (DFA/NFA) as regular expressions can be converted to automata to recognize tokens.


9. Which of the following items are stored in the symbol table?
(A) Variable names and constants from the source program
(B) Procedure and function names from the source program
(C) Label names present in the source program
(D) All of the above mentioned
✔️Answer: D

📝 Explanation:
A symbol table keeps all identifiers — variable names, function names, labels — and their attributes (like type, scope, etc.)


10. Suppose that the access time of an implemented symbol table is logarithmic. Then the symbol table has been implemented using:
(A) Search tree
(B) Linear list
(C) Hash table
(D) None of the above
✔️Answer: A

📝 Explanation:
A search tree like a binary search tree (BST) gives O(log n) access time.

  • Hash table has O(1) average time
  • Linear list is O(n)

11. Which of the following can be managed fully during compilation?
(A) Static memory allocation
(B) Dynamic memory allocation
(C) Both (A) and (B)
(D) Neither (A) nor (B)
✔️Answer: A

📝 Explanation:
Static memory like global variables can be allocated at compile time.
Dynamic memory is handled at runtime via malloc, new, etc.


12. Which of the following is NOT TRUE in the context of syntax analysis phase of compilation?
(A) Input to the syntax analysis phase are tokens from lexical analyzer
(B) Syntax analysis phase checks syntactic (grammatical) correctness
(C) It checks if the input program can be derived from the start symbol of a grammar using the grammar rules
(D) Syntax analysis phase can determine if a variable is declared before it is being used
✔️Answer: D

📝 Explanation:
Syntax analysis only checks grammar rules.
Detecting use-before-declaration is a semantic analysis task, not syntax.