Difficulty: Easy
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:
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:
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.
Discussion & Comments