All Exams Test series for 1 year @ ₹349 only
Question

Arrange the following tasks of Lexical Analyzer in correct sequence: 

A. Token Generation. 

B. Removal of comments/White sphere. 

C. Buffering and reading source characters. 

D. Return token stream to parser.

The correct answer is
C, B, A, D

Lexical Analyzer Tasks Sequence

The Lexical Analyzer, often called a lexer, is the first phase of a compiler. Its primary role is to read the source code and convert it into a stream of tokens. The tasks involved follow a specific order:

  • C. Buffering and reading source characters: This is the initial step. The lexical analyzer reads the source code character by character, often using buffering techniques for efficiency, to get the raw input program.
  • B. Removal of comments/White space: After reading the characters, the analyzer identifies and discards comments and white space (spaces, tabs, newlines). These elements are typically ignored as they are not significant for the subsequent parsing phase.
  • A. Token Generation: The analyzer processes the cleaned stream of characters to identify meaningful lexemes (sequences of characters) and generates corresponding tokens. Tokens represent syntactic units like keywords, identifiers, operators, constants, etc.
  • D. Return token stream to parser: Once tokens are generated, the lexical analyzer outputs this stream of tokens to the next phase of the compiler, the parser, which uses them to check the grammatical structure of the program.

Therefore, the correct sequence of tasks is C, B, A, D.

Was this answer helpful?
Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App