NPTEL Compiler Design Week 1 And 2 Assignment Answers 2025

NPTEL Compiler Design Week 1 And 2 Assignment Answers 2025

1. Which phase of compiler does NOT use symbol table?

  • a) Code generation
  • b) Syntax Analysis
  • c) Lexical Analysis
  • d) None of the other options
    ✅ Answer: d
    Explanation: All phases of the compiler do use the symbol table in some way — from token storage in lexical analysis to variable/type usage in code generation.

2. Which phase of compiler is Syntax Analysis?

  • a) First
  • b) Second
  • c) Third
  • d) None of the mentioned
    ✅ Answer: b
    Explanation: The second phase after Lexical Analysis is Syntax Analysis, also known as parsing.

3. Output of the syntax analysis is called

  • a) Parse tree
  • b) Keyword tree
  • c) Binary tree
  • d) All of the other options
    ✅ Answer: a
    Explanation: Syntax analysis generates a parse tree, representing grammatical structure.

4. Language doesn’t allow integer division. Detected in which phase?

  • a) Lexical Analysis
  • b) Syntax Analysis
  • c) Semantic Analysis
  • d) None of the other options
    ✅ Answer: c
    Explanation: Semantic Analysis checks meaning and legality, including invalid operations.

5. Which is not true about Symbol Table?

  • a) All labels are symbols
  • b) Table includes name, address, value
  • c) Performs processing of assembler directives
  • d) Created during pass 1
    ✅ Answer: c
    Explanation: Symbol table does not process assembler directives; that’s done by assembler phases.

6. A compiler can check

  • a) Logical error
  • b) Syntax error
  • c) Both
  • d) Neither
    ✅ Answer: b
    Explanation: Logical errors are not detectable by compiler; only syntax/semantic errors can be.

7. Error recovery helps to

  • a) Report multiple errors
  • b) Rectify multiple errors
  • c) Both
  • d) None
    ✅ Answer: a
    Explanation: Error recovery tries to report as many errors as possible, not fix them.

8. Converting hardware description into actual circuitry is

  • a) Silicon Compilation
  • b) HDL Compilation
  • c) Circuit Compilation
  • d) None
    ✅ Answer: a
    Explanation: Silicon Compilation automatically converts HDL to physical chip layout.

9. Loops are major targets for optimization because

  • a) Infinite execution
  • b) Repeated many times
  • c) Condition check takes long
  • d) None
    ✅ Answer: b
    Explanation: Loop optimization yields maximum performance gain due to repetition.

10. For max speed, where to store temporary variables?

  • a) Swap space
  • b) Main memory
  • c) CPU registers
  • d) None
    ✅ Answer: c
    Explanation: CPU registers are fastest storage for temporaries.

11. Intermediate code helps in

  • a) Program Analysis
  • b) Code optimization
  • c) Retargeting code
  • d) Code check
    ✅ Answer: c
    Explanation: Intermediate code allows easier porting to different architectures.

12. Output file of Lex if input is Myfile

  • a) Myfile.e
  • b) Myfile.yy.c
  • c) Myfile.lex
  • d) Myfile.obj
    ✅ Answer: b
    Explanation: Lex generates Myfile.yy.c by default, containing the C source code.

NPTEL Compiler Design Week 2 Assignment Answers

1. A regular expression represents

  • a) Part of a language
  • b) Cannot represent any language
  • c) Constituent strings of a language
  • d) None of the other options
    ✅ Answer: c
    Explanation: Regular expressions describe all valid strings (constituents) of a regular language.

2. Token category of 3 in sum = 3 + 2

  • a) Identifier
  • b) Assignment operator
  • c) Integer literal
  • d) Addition operator
    ✅ Answer: c
    Explanation: 3 is an integer literal, a constant numerical value in tokenization.

3. In Fortran statement DO 5 I = 1.25, when is DO 5 I interpreted as identifier?

  • a) 1
  • b) =
  • c) . (dot)
  • d) 5
    ✅ Answer: c
    Explanation: In Fortran, if the parser sees 1.25, the presence of the dot (.) distinguishes it as a floating-point number, not a DO loop.

4. Which of the following are Lexemes?

  • a) Identifiers
  • b) Constants
  • c) Keywords
  • d) All of the mentioned
    ✅ Answer: d
    Explanation: Lexemes are actual character sequences that form tokens like keywords, identifiers, constants, etc.

5. Regular expression for strings with one more 1 than 0’s

  • a) 01
  • b) (0|1)1(0|1)
  • c) (0|1)1(0|1)|1(0|1)*
  • d) Not Possible
    ✅ Answer: d
    Explanation: Regular expressions cannot count or enforce numerical relationships like “exactly one more 1 than 0s”.

6. Language described by (0+1)0(0+1)0(0+1)

  • a) Strings with substring 00
  • b) At most two 0’s
  • c) At least two 0’s
  • d) Strings beginning and ending with 0 or 1
    ✅ Answer: c
    Explanation: The expression ensures at least two 0’s anywhere in the string.

7. Finite automata is an implementation of

  • a) Regular expression
  • b) Any grammar
  • c) Part of the regular expression
  • d) None
    ✅ Answer: a
    Explanation: Finite automata and regular expressions are equivalent in expressive power.

8. Automaton that allows state transition without input consumption

  • a) NFA
  • b) DFA
  • c) PDA
  • d) All of the mentioned
    ✅ Answer: a
    Explanation: NFAs allow ε (epsilon or null) transitions without reading input.

9. Set of states reachable from P via ε-transitions

  • a) ε-closure
  • b) ε-spark
  • c) Q in the tuple
  • d) None
    ✅ Answer: a
    Explanation: ε-closure includes all states reachable via epsilon transitions from a given set.

10. Power comparison between NFA and DFA

  • a) NFA
  • b) DFA
  • c) Equally powerful
  • d) Cannot say
    ✅ Answer: c
    Explanation: Both DFA and NFA recognize the same set of regular languages.

11. Subset Construction Method refers to

  • a) Conversion of NFA to DFA
  • b) DFA minimization
  • c) Null removal
  • d) ε-NFA to NFA
    ✅ Answer: a
    Explanation: Subset construction method is used for converting NFA to equivalent DFA.

12. Construction method for NFA from regular expression

  • a) Subset construction
  • b) Powerful set construction
  • c) Thompson construction
  • d) Scott construction
    ✅ Answer: c
    Explanation: Thompson’s Construction builds NFA from a regular expression.

13. Compiler correcting “fi” to “if” is recovery by

  • a) Panic mode
  • b) Delete character
  • c) Replace character
  • d) Transpose character
    ✅ Answer: d
    Explanation: Changing fi to if involves transposing characters, a common error recovery technique.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top