What is Compiler
Compiler is a program which takes one language (source program) as input and translates it into an equivalent another language (target program).
Compiler is a program which takes one language (source program) as input and translates it into an equivalent another language (target program).
During this process of translation if some errors
are encountered then compiler displays them as error messages, The basic
model of compiler can be represented as follows.
The compiler takes a source program such as higher level languages
such as C, PASCAL. FORTRAN and converts it into low level language or a
machine level language such as assembly language.
Structure of Compiler
The compilation can be done in two parts : Analysis and synthesis, In
analysis part the source program is read and broken down into
constituent pieces, The syntax and the meaning of the source
string is detenruned and then an intermediate code is created
from the input source program. In synthesis put this internediate form
of the source language is taken and converted into an equivalent target
program. During this process if certain code has to be optimized for
efficient execution then the required code is optimized. The analysis
and synthesis model is as shown in Fig
The analysis part is carried out in three sub parts
1. Lexical Analysis- In
this step the source program is read and then it is broken into stream
of strings. Such strings are called tokens. Hence tokens are nothing but
only collection of characters having some meaning.
2. Syntax Analysis -In this step the tokens are arranged in hierarchial structures that ultimately helps in finding the syntax of the source string.
3. Semantic Analysis - In this step the meaning of the source string is determined
In all these analysis steps the meaning of
the every source string should be unique. Hence actions in lexical,
syntax and semantic analysis are uniquely defined for a given language.
After carrying out the synthesis phase the program gets executed.
Execution of Program
To create an executable form of your source program only a compiler
program is not sufficient.You may require several other programs to
create an executable target program. After a synthesis phase a target
code gets generated by the compiler. This target program generated by
the compiler is processed further before it can be run which is as shown
in the Fig.
The compiler takes, a source program written in high level language
as an input and converts it into a target assembly language. The
assembler then takes this assembly code as input and produces
relocatable machine code as output. Then program loader is called for
perfoming the task of loading and link editing. The
task of loader is to pedict the relocation of an object code. Relocation
of an object code means allocation of load time addresses which exist
in the memory and placement of Ioad time addresses and and data in
memory at proer location.. The link editor links the object module and
prepares a single module from several files of relocatable
object modules to resolve the mutual references. These files may be
library files and these files may be referred by any program.
No comments:
Post a Comment