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.


