What is the primary task of a lexical analyzer in a compiler ?

2024

What is the primary task of a lexical analyzer in a compiler ?

  1. A.

    Identifies tokens based on keywords and identifiers

  2. B.

    Checks the semantic meaning of expressions

  3. C.

    Generates optimized machine code

  4. D.

    Builds the abstract syntax tree of the program

Attempted by 52 students.

Show answer & explanation

Correct answer: A

The primary task of a lexical analyzer is to read the source code character by character and convert it into meaningful tokens. It identifies keywords, identifiers, operators, and literals while removing whitespace and comments.

Explore the full course: Niacl Ao It Specialist