Home » Compiler Design

Compilers Introduction, Cousins and Phases

In this article, we are going to learn about compilers - its introduction, cousins of compilers and phases of compilers.
Submitted by Anusha Sharma, on March 19, 2018

Translators

A software system which converts the source code from one form of language to another form of language is known as translator.

There are three types of translator:

  1. Assembler
  2. Compiler
  3. Interpreter

Compiler

It is a translator which converts the source code from high level of language to low level language.

Assembler

It is software which converts assembly code into object code, is called assembler.

Cousins of Compiler

Cousins of Compiler

1) Preprocessor

It converts the HLL (high level language) into pure high level language. It includes all the header files and also evaluates if any macro is included. It is the optional because if any language which does not support #include and macro preprocessor is not required.

2) Compiler

It takes pure high level language as a input and convert into assembly code.

3) Assembler

It takes assembly code as an input and converts it into assembly code.

4) Linking and loading

It has four functions

  1. Allocation:
    It means get the memory portions from operating system and storing the object data.
  2. Relocation:
    It maps the relative address to the physical address and relocating the object code.
  3. Linker:
    It combines all the executable object module to pre single executable file.
  4. Loader:
    It loads the executable file into permanent storage.

Phases of compiler

It is define as the converting the source code from one form of representation to another is called phase.

Phases of compiler

Image source: https://www.slideshare.net/Saikatcsebd/phases-of-a-compiler

  1. Lexical analysis:
    It scans the source code and converts the source code into tokens. Here, input is source code and output is stream of tokens.
  2. Syntax Analysis:
    After converting the source code into tokens, the next phase comes i.e. syntax analysis. It checks the grammaratical mistake of the source code. To verify the syntax of the source code the language must be defined by CFG. It takes streams of input as a input and generates parse tree.
  3. Symantic Analysis:
    It verifies the meaning of each and every sentence by performing type check. Syntax analyzer just verifies whether the operator is operating on required number of operands or not.
  4. Intermediate Code Generator:
    The source code is converted into intermediate representation to make code generation process simple and easy.
  5. Code Optimization:
    This process includes in reducing the number of instruction without affecting the outcome of source program.
  6. Target Code Generator:
    The optimization source code should convert into assembly code.


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.