Question

    What does a lexer (lexical analyzer) do in the

    compilation process?
    A Generates optimized machine code Correct Answer Incorrect Answer
    B Checks for semantic errors Correct Answer Incorrect Answer
    C Converts high-level code to assembly language Correct Answer Incorrect Answer
    D Converts source code into a stream of tokens Correct Answer Incorrect Answer
    E None of these Correct Answer Incorrect Answer

    Solution

    A lexer (lexical analyzer) is responsible for converting the source code into a stream of tokens. It identifies keywords, operators, identifiers, and other language constructs, producing a structured representation that's easier for the subsequent compilation phases to process.

    Practice Next

    Relevant for Exams: