Q61.Marks: +2.0UGC NET Paper 2: Computer Science 2nd January 2026 Shift 1
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.
Choose the correct answer from the options given below:
1.A, B, C, D
2.B, A, C, D
3.C. B. A, D✓ Correct
4.B. A. D. C
Solution
The correct answer is C. B. A. D.
Key Points
The correct sequence for the tasks of a lexical analyzer is C. B. A. D.
The lexical analyzer begins by buffering and reading source characters (step C).
Next, it performs the removal of comments/white spaces to clean up the input (step B).
Then, it proceeds with token generation, breaking the input into meaningful components (step A).
Finally, it returns the token stream to the parser for further processing (step D).
Additional Information
Detailed Explanation of Steps:
Step C (Buffering and reading source characters): The lexical analyzer reads the source program character by character, often using a buffering mechanism to manage input efficiently.
Step B (Removal of comments/white spaces): Non-essential elements like comments and white spaces are removed to simplify the input for subsequent stages.
Step A (Token generation): The cleaned-up input is divided into tokens, which are the smallest units of meaning (e.g., keywords, identifiers, operators).
Step D (Return token stream to parser): The generated tokens are passed to the parser, which constructs a syntax tree or other intermediate representation.
Role of Lexical Analyzer:
The lexical analyzer is the first phase of a compiler, responsible for converting source code into a sequence of tokens.
It ensures that the input is free of irrelevant characters, simplifying the tasks of subsequent phases like parsing and semantic analysis.
Additional Considerations:
Efficient buffering techniques are crucial for the performance of the lexical analyzer, especially for large programs.
Error handling is another important aspect, such as reporting invalid characters or malformed tokens.