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 ?
- A.
Identifies tokens based on keywords and identifiers
- B.
Checks the semantic meaning of expressions
- C.
Generates optimized machine code
- 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.