Introduction to Compiler

Three types of translater

  1. Compiler => used in High level language
  2. Interpreter => used in High level language
  3. Assembler => used in Assembly language

Why study compiler design not interpreter

compilation:

  1. translate source code into object code as whole
  2. It create object file
  3. execution is fast
  4. Program is not required to translate each time to run
  5. Error diagonosis is poor
  6. Most HLL uses compiler

Interpreter:

  1. It translate the statement of source one by one and execute intermediate
  2. It doesn’t create object file
  3. Execution is slow
  4. required to translate hte program each time to run
  5. error dignosis is better
  6. few HLL uses Interpreter

Phases of Compiler

  1. Lexical Analysis

    Lexical analysis is the first phase of a compiler. It takes modified source code from language preprocessors that are written in the form of sentences. The lexical analyzer breaks these syntaxes into a series of tokens, by removing any whitespace or comments in the source code.

    If the lexical analyzer finds a token invalid, it generates an error. The lexical analyzer works closely with the syntax analyzer. It reads character streams from the source code, checks for legal tokens, and passes the data to the syntax analyzer when it demands.

    This is the

  2. Syntax Analysis

  3. Symentic Analysis

  4. Intermediate code generator

  5. Code optimizer

  6. Code Generator

Pass of Compiler

  1. Single Pass Compiler

  2. Two-Pass Compiler