What is Compiler?

What is Language Translator?

Language translation is the process of converting program written in a high level language into machine language. Computer understands machine language only which is written in 0 and 1.

What is Compiler?

Actually there are two types of computer languages one is lower level language it is also called as assembly language program in assembly language is written using assembly language instructions, another type is higher level languages like c, java tec. It is very difficult to write program in assembly level language. To solve this problem we use compiler a compiler is a program which that reads a program written in source language and translates it into program in machine language it also detects errors in program. Compilation can be divided into two parts analysis phase and synthesis phase.

Interpreter

Interpreter is also one kind of translator it accepts source program and convert it into machine code but important difference between interpreter and compiler is that interpreter translates program one line at a time on the other hand compiler translates the entire code into machine code.

 

Types of Compiler

 

Bootstrap Compiler

Bootstrap compiler is develop in a language which it is intended to compile for example we want to implement new language first we will write a working compiler in machine code this will translates some part of language into target code of machine now we have small compiler we can use this compiler for language transition we can use this small part to write full compiler.

 

Cross Compiler

Suppose we have a machine like microcontroller which does not support compiler or it is not feasible to place compiler in it. In this case we cross compile which creates executable code for machine other than one on which it runs.

 

Compiler

 

Phases of Compiler

 

  • Lexical Analyser

In lexical analysis compiler scans source program from left to right and separates program in to tokens. Consider following C statement

 

X=A+B;

X is identifier

= is terminal

+ is terminal

B is identifier

; is terminal

 

After scanning lexical analyser creates various tables like literal table literal table stores literal, identifier table stores the identifiers, and terminal table stores the terminals.

 

  • Syntax Analysis

In this phase compiler check weather all statements in the program are written as per the grammar or not. Compiler built the parse tree where operators are represented as node and operand represented as leaf.

 

  • Semantic Analysis

 

Semantic analyser check logical errors like we cannot multiply two pointers, we cannot multiply string and integer; we cannot use real number as index of an array. If it detects unexpected data type it automatically converts into desirable data type.

 

  • Intermediate Code Generator

Before converting program into machine code the compiler converts source program into intermediate code there are various forms of intermediate code like

  1. Three address code
  2. Quadruple
  3. Triple
  4. Postfix
  5. Syntax tree

 

  • Code Optimization

Code optimization is the process of improving the program so that it can get execute faster and use less memory code can be optimized using various techniques. For more reading about technology news in singapore and seo to online marketing do view more about other pages.

Written by Sourabh Bhunje

Sourabh Bhunje, B.E. IT from Pune University. Currently Working at Techliebe. Professional Skills: Programming - Software & Mobile, Web & Graphic Design, Localization, Content Writing, Sub-Titling etc. http://techliebe.com/about-us

Leave a Comment