All Exams Test series for 1 year @ ₹349 only
Question

Which of the following not correct according to input to output, the compiler phase that is processes by it?

Phases of CompilerInputOutput
ALexical AnalyzerCharacter streamToken stream
BSyntax AnalyzerToken streamSyntax tree
CSemantic AnalyzerSyntax treeSyntax tree
DIntermediate Code GeneratorSyntax treeTarget-machine code

The correct answer is

D

Let's analyze the different phases of a compiler and their typical inputs and outputs to determine which statement is not correct.

Compiler Phases and Their Input/Output

A compiler translates source code written in a high-level programming language into low-level machine code. This process is broken down into several distinct phases. Let's look at the inputs and outputs for the phases mentioned in the question.

Phase of Compiler Input Output
Lexical Analyzer Character stream Token stream
Syntax Analyzer Token stream Syntax tree
Semantic Analyzer Syntax tree Syntax tree (often annotated)
Intermediate Code Generator Syntax tree Target-machine code

Analysis of Each Compiler Phase Mapping

  • Lexical Analyzer: This phase, also known as scanning, reads the input character stream and groups characters into meaningful sequences called tokens. So, the input is the character stream, and the output is the token stream. This mapping is correct.
  • Syntax Analyzer: This phase, also known as parsing, takes the token stream from the lexical analyzer and builds a tree structure, typically a syntax tree (or parse tree/abstract syntax tree), that represents the grammatical structure of the code. So, the input is the token stream, and the output is a syntax tree. This mapping is correct.
  • Semantic Analyzer: This phase checks the syntax tree for semantic errors, such as type mismatches, undeclared variables, etc. It also gathers type information and performs type checking. The output is typically an annotated syntax tree, where type information is added or errors are flagged. Saying the output is a syntax tree is generally correct as it's the same structure but with added information. This mapping is correct.
  • Intermediate Code Generator: This phase takes the (annotated) syntax tree and translates it into an intermediate representation of the source code. This intermediate code is typically independent of the target machine architecture. Examples include three-address code, quadruples, or triples. The output of this phase is intermediate code, not target-machine code. Target-machine code is generated by the subsequent phase, the Code Generator. Therefore, the mapping provided for the Intermediate Code Generator is incorrect.

Identifying the Incorrect Mapping

Based on the standard compiler phases and their functions, the mapping for the Intermediate Code Generator is incorrect because its output is intermediate code, not target-machine code. The description in the table states that the Intermediate Code Generator's output is Target-machine code, which is the output of the final Code Generation phase.

Thus, the description for the Intermediate Code Generator is the one that is not correct according to the input to output process in compiler phases.

Was this answer helpful?

Important Questions from Syntax Analyzer

  1. Match the description of several parts of a classic optimizing compiler in List - I, with the names of those parts in List - II:

    List - I

    List - II

    A. A part of a compiler that is responsible for recognizing

    1. Optimizer syntax

    B. A part of a compiler that takes as input a stream of characters and produces as output a stream of words along with their associated syntactic categories.

    2. Semantic Analysis

    C. A part of a compiler that understands the meanings of variable names and other symbols and checks that they are used in ways consistent with their definitions.

    3. Parser

    D. An IR-to-IR transformer that tries to improve the IR program in some way (Intermediate Representation).

    4. Scanner

  2. Shift-Reduce parsers perform the following :

  3. Which phase of compiler generates stream of atoms ?

  4. Match List I with List II

    List IList II
    A. Initial Configuration of stack and input in LL Parsing process.I. \(\$\) w\(\$\)
    B. Final Configuration of stack and input in LL Parsing processII. \(\$\) \(\$\)
    C. Initial Configuration of stack and input in LR Parsing processIII. \(\$\)S w\(\$\)
    D. Final Configuration of stack and input in LR Parsing processIV. \(\$\)S \(\$\)

    Choose the correct answer from the options given below:

  5. While processing a string by an LR parser, the reading of the given string by the parser is--------------.

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App