In the compilation of a PL/I (or similar) program, what does the Lexical Analysis phase primarily accomplish?
-
Arecognition of basic syntactic constructs through reductions
-
Brecognition of basic elements and creation of uniform symbols
-
Ccreation of more optimal matrix
-
Duse of macro processor to produce more optimal assembly code
-
ENone of the above
Answer
Correct Answer: recognition of basic elements and creation of uniform symbols
Explanation
Introduction / Context:Compilers transform high-level source code into executable form through a pipeline of phases. The first substantive phase after preprocessing is lexical analysis (scanning), which converts raw character streams into tokens for the parser.
Given Data / Assumptions:
- Source language is PL/I or a similar high-level language.
- We distinguish between lexing (tokens) and parsing (syntactic structures).
- Uniform symbols (tokens) are the standardized representation of basic language elements.
Concept / Approach:
Lexical analysis groups characters into meaningful units: identifiers, keywords, literals, operators, delimiters. It may also remove whitespace/comments and normalize representations (e.g., number formats). The output is a token stream, often with symbol table entries for identifiers and literals, which feeds the parser for grammar-based analysis.
Step-by-Step Solution:
Define lexing: character stream -> token stream.Identify outputs: uniform symbols/tokens, optional symbol table entries.Contrast with parsing: reductions and grammar rules are parser responsibilities.Select the option that describes token recognition and uniform symbol creation.Verification / Alternative check:
Standard compiler design references separate scanner and parser phases exactly along these lines.
Why Other Options Are Wrong:
- syntactic reductions: parser activity.
- optimal matrix / macro processor: optimization and macro expansion are separate concerns.
Common Pitfalls:
- Mistaking symbol table construction as purely lexical; parser and semantic phases also contribute entries—lexing focuses on tokens.
Final Answer:
recognition of basic elements and creation of uniform symbols.