Role of the Lexical Analyzer MCQs

  1. What is the primary function of the lexical analyzer in the compilation process?
    a) Convert high-level code to machine code
    b) Translate the source code into intermediate code
    c) Divide the source code into meaningful tokens
    d) Perform error checking and recoveryAnswer: c) Divide the source code into meaningful tokens
  2. Which of the following tasks is NOT performed by the lexical analyzer?
    a) Identifying keywords and operators
    b) Generating intermediate code
    c) Identifying identifiers and constants
    d) Removing whitespace and commentsAnswer: b) Generating intermediate code
  3. What does the lexical analyzer use to match input patterns and generate tokens?
    a) Pushdown automata
    b) Finite automata
    c) Context-free grammar
    d) Turing machinesAnswer: b) Finite automata
  4. How does the lexical analyzer handle whitespace and comments in the source code?
    a) It removes them to simplify the analysis process
    b) It treats them as tokens for error detection
    c) It includes them as part of the token list
    d) It translates them into machine codeAnswer: a) It removes them to simplify the analysis process
  5. Which of the following is an output of the lexical analysis phase?
    a) A parse tree
    b) A list of tokens
    c) Intermediate code
    d) An abstract syntax treeAnswer: b) A list of tokens
  6. What is the role of regular expressions in the lexical analysis process?
    a) Define the syntax of the source code
    b) Specify patterns for token recognition
    c) Perform error checking during compilation
    d) Optimize the code for executionAnswer: b) Specify patterns for token recognition
  7. What happens when the lexical analyzer encounters an invalid token?
    a) It generates an error and stops the compilation process
    b) It ignores the token and continues analyzing the code
    c) It tries to repair the token by modifying it
    d) It reports a lexical error to the syntax analyzerAnswer: d) It reports a lexical error to the syntax analyzer
  8. In which phase of compilation does the lexical analyzer operate?
    a) Code generation
    b) Semantic analysis
    c) Lexical analysis
    d) Syntax analysisAnswer: c) Lexical analysis
  9. Which of the following does the lexical analyzer NOT do?
    a) Recognize tokens such as keywords and identifiers
    b) Perform syntax checking
    c) Remove unnecessary whitespace and comments
    d) Pass tokens to the syntax analyzerAnswer: b) Perform syntax checking
  10. What is the role of the symbol table in lexical analysis?
    a) It stores the generated machine code
    b) It stores identifiers and their attributes
    c) It is used for semantic checking
    d) It stores intermediate representations of the codeAnswer: b) It stores identifiers and their attributes

Leave a Reply

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