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 ?
Answer: A. Identifies tokens based on keywords and identifiers — 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,…
- 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 319 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.
Loading lesson…