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

COMPILER is used to?

The correct answer is

convert high level into low level language

Compiler Function Explained

A compiler is a crucial tool in computer programming. Its primary job is to translate source code written in a high-level programming language (like C++, Java, Python) into a low-level language that the computer's processor can understand and execute, typically machine code or an intermediate code.

Understanding Language Levels

  • High-Level Languages: These are languages that are closer to human language and easier for programmers to write and understand. They use words, phrases, and syntax similar to English. Examples include Python, Java, C++, and Ruby.
  • Low-Level Languages: These languages are much closer to the hardware. They include:
    • Assembly Language: Uses mnemonics (short abbreviations) to represent machine instructions.
    • Machine Language: Consists of binary code (0s and 1s) that the processor directly executes.

How a Compiler Works

The compiler takes the entire source code written in a high-level language and goes through several stages:

  1. Lexical Analysis: Reads the source code and breaks it down into smaller units called tokens.
  2. Syntax Analysis (Parsing): Checks if the tokens form valid statements according to the language's grammar rules. It often creates a parse tree.
  3. Semantic Analysis: Checks the code for logical errors and ensures it makes sense, like type checking.
  4. Intermediate Code Generation: Creates a machine-independent intermediate code.
  5. Code Optimization: Improves the intermediate code to make it run faster and use less memory.
  6. Code Generation: Translates the optimized intermediate code into the target low-level language (e.g., machine code or assembly language).

The output of the compiler is an executable file that the computer can run directly.

Comparing Compiler Functionality

Let's look at why the other options are less accurate:

  • Option 1: convert low level into high level language - This is the opposite of what a compiler does. Compilers translate from human-readable high-level code to machine-readable low-level code.
  • Option 3: translate assembly language into machine language - This is the job of an assembler, not a compiler. Compilers typically start with high-level languages.
  • Option 4: none of these - Since Option 2 accurately describes the compiler's function, this option is incorrect.

Therefore, the primary role of a compiler is to convert high-level language into low-level language, making the code executable by the computer.

Was this answer helpful?

Important Questions from Syntax Directed Translation

  1. Given the following syntax directed translation rules:
    Rule 1: $R \to AB$ {$B. i = R. i - 1$; $A. i = B. i$; $R. i = A. i + 1$; }
    Rule 2: $P \to CD$ {$P.i = C.i + D.i$; $D. i = C. i + 2$; }
    Rule 3: $Q \to EF$ {$Q.i = E.i + F. i$; }
    Which ONE is the CORRECT option among the following?
  2. In which graph, semantic rules set up dependencies between attributes ?
  3. Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations.

    SDD1
    Grammar (G1)Semantic Rules
    $D \rightarrow T\ V$$D.type = T.type$
    $V.type = T.type$
    $T \rightarrow int$$T.type = int$
    $T \rightarrow float$$T.type = float$
    $V \rightarrow V_1\ id$$V_1.type = V.type$
    $put(id.entry, V.type)$
    $V \rightarrow id$$put(id.entry, V.type)$

    SDD2
    Grammar (G2)Semantic Rules
    $D \rightarrow D_1\ id$$D.type = D_1.type$
    $put(id.entry, D_1.type)$
    $D \rightarrow T\ id$$D.type = T.type$
    $put(id.entry, T.type)$
    $T \rightarrow int$$T.type = int$
    $T \rightarrow float$$T.type = float$

    $D$ is the start symbol, and $int$, $float$ and $id$ are the three terminals. The non-terminal $V_1$ is the same as $V$ and the non-terminal $D_1$ is the same as $D$. Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function $put$ updates the symbol table with the type information for an identifier.
    Let P and Q be the languages specified by grammars G1 and G2, respectively.
    Which of the following statements is/are true?
  4. Which of the following statement(s) are correct?

    A. Syntax Directed Translation can be applied in Type Checking.

    B. Syntax Directed Translation can be used in 3-address code generation.

    C. Syntax Directed Translation can be used in construction of syntax tree.

    D. Syntax Directed Translation can be used to recognize valid tokens.

    Choose the most appropriate answer from the options given below:

  5. Which of the following tasks could be attained using syntax trees in compiler design ?

    (A) Type Checking

    (B) Code Generation

    (C) Code Optimization

    (D) Error Handling

    Choose the correct answer from the options given below :

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