Compiler construction: during analysis of a PL/I program, lexical analysis refers to which specific activity in the front-end pipeline?
-
Arecognition of basic syntactic constructs through reductions
-
Brecognition of basic elements and creation of uniform symbols
-
Ccreation of more optional 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 typically perform a front-end pipeline: lexical analysis (scanning), parsing (syntax analysis), and semantic analysis, followed by intermediate representation and code generation/optimization. This question focuses on the first step—lexical analysis—and asks you to identify its primary purpose.
Given Data / Assumptions:
- Source language is PL/I, but the general principles apply to most languages.
- We are distinguishing scanning from parsing and later phases.
- Macro processing and code optimization are separate concerns.
Concept / Approach:Lexical analysis converts a raw character stream into a sequence of tokens (uniform symbols) such as identifiers, keywords, literals, operators, and punctuation. This token stream is then consumed by the parser. The scanner also performs tasks like skipping whitespace/comments and possibly normalizing numeric literals or case, depending on language rules.
Step-by-Step Solution:1) Start with a character sequence from the source file.2) Group characters into meaningful units (tokens) using regular patterns (e.g., identifier = letter (letter|digit)*).3) Emit a stream of uniform symbols (token kind + lexeme/attributes) for the parser.4) Leave syntactic structure (grammar productions and reductions) to the parser, not the lexer.
Verification / Alternative check:Standard compiler texts define lexical analysis (scanning) as tokenization. Tools like lex/flex embody this by generating scanners that recognize token patterns and return uniform symbols to the parser (yacc/bison).
Why Other Options Are Wrong:
- Syntactic reductions: That is parsing (syntax analysis), not scanning.
- “Optional matrix”: Not a standard compiler term in this context.
- Macro processor: Preprocessing or macro expansion is separate and not lexical analysis.
- None of the above: Incorrect because token recognition and uniform symbol creation is exactly lexical analysis.
Common Pitfalls:Blurring the boundary between lexing and parsing can cause design bugs; keep tokenization concerns distinct from grammar recognition and semantic checks.
Final Answer:recognition of basic elements and creation of uniform symbols.