Consider the following two sets:
Set XP. Lexical AnalyzerQ. Syntax AnalyzerR. Intermediate Code Generator S. Code OptimizerSet Y1. Abstract Syntax Tree2. Token3. Parse Tree4. Constant Folding Which one of the following options is the CORRECT match from Set X to Set Y ?
📖 Explanation
Let's match each component of Set X (phases of a compiler) with its output in Set Y.
P. Lexical Analyzer: This phase performs lexical analysis, which involves scanning the source code and grouping characters into meaningful units called tokens. So, P matches 2 (Token).
Q. Syntax Analyzer: This phase performs syntax analysis (parsing), taking tokens as input and building a parse tree or abstract syntax tree to represent the grammatical structure. So, Q matches 3 (Parse Tree).
R. Intermediate Code Generator: This phase generates an intermediate representation of the source code, which is typically platform-independent and easier to optimize. Abstract Syntax Tree is one such intermediate representation. So, R matches 1 (Abstract Syntax Tree).
S. Code Optimizer: This phase attempts to improve the intermediate code so that faster or smaller machine code can be produced. Constant folding is a type of optimization where constant expressions are evaluated at compile time. So, S matches 4 (Constant Folding).
Therefore, the correct mapping is P-2, Q-3, R-1, S-4.




