Tuesday, July 29, 2008

Lecture Notes-1

Compiler Design
Unit-I

Lecture-1

Introduction to Compiler & Translators:

Translator:
A translator is a program that takes as input a program written in one programming language i.e. Source language & produces as output a program in another language i.e. Object or target language.

Types of Translators:

Translators are generally classified into three types

1) Compiler
2) Interpreter
3) Assembler

Compiler:

Compiler is a program that translates a high level language program into a functionally equivalent low level language program.
So a Compiler is basically a translator whose source language is the high level language and the target language is a low level language, such as an assembly language or machine language.



COMPILERSource program Object program
Written in high Written in low
Level language level language


Error Message

The Compiler reports to its user the presence of errors in the source program.


Interpreter:

Interpreter is a translator which translates high level language program into low level language program line by line & also interpreter executes the program.



Assembler:

Assembler is a translator which translates assembly language program into a functionally equivalent machine language program.



ASSEMBLERAssembly language Machine language
Program program


Difference between Compiler & Interpreter:

Compiler

Interpreter
Compiler translates the high level language program into low level language program whole at a time.

Interpreter translates the high level language program into low level language program line by line.
It can not execute a program
It can execute a program

It works fast as whole program is converted at a time.
It works slowly as line by line conversion occurs.

Chances of error finding are less.


Chances of error finding are more.

Cross Compiler:
A cross compiler is a Compiler that runs on one machine & produces object code for another machine.

The cross compiler is used to implement the Compiler, which is characterized by three languages:

1) The Source language
2) The Object language
3) The language in which it is written.



BootStrap Compiler:

If a Compiler has been implemented in its own language , then this Compiler is called bootstrap Compiler.

Implementing a bootstrap Compiler:

Suppose we have a new language L that we want to make available on machine A and B.
As a first step, we can write a small compiler SCAA, which will translate an S subset of L to the object Code for machine A, written in a language available on A.

We then write a compiler SCSA, which is compiled in language L and generates object code written in an S subset of L for machine A, But this will not be able to execute unless and until it is translated by SCAA. Therefore SCSA is an input into SCAA. As shown below, producing a compiler for L that will run a machine A and self generate code for machine A.

SCSA à SCAA à LCAA9 -

No comments: