Sei sulla pagina 1di 10

Compilers

A computer program that transforms source code written in a


high level computer programming language into object code, a
low level computer language having a binary form.

Y ou w rite this The com puter translates...itinto this, w hich it can run
How it is done?
The compiler takes the file that we
have written translates it and produces
another file from it.
For example in the case of Pascal
programs, we might write a program called
myProg.pas and the Pascal compiler
would translate it into the file myProg.exe
which we could run.
Compilers also checks the program to
make sure that it is grammatically correct. Only
when it is sure that there are no grammatical
errors does it do the translation.
If there is any error (compile-time errors or
syntax errors) compiler generates an error
message and is displayed on the screen. Only
after correcting all the errors the compiler
create the object code.
Stages of processing
Tokenising Syntax analysis Semantic
analysis Translation
 Tokenising:- Also known as lexical
analysis. It involves turning the program
from a series of characters into a series of
tokens that represent the building blocks of
a program and reports it to the next stage
of the process . The tokens are keywords
of the language i.e. important words such
as if, print or repeat, variable names and
mathematical operators (+, *, brackets
etc.).
 Syntax analysis :- The syntax analyser in
a compiler checks that the right tokens
appear in the right order to make
grammatically correct instructions
 Semantic Analysis :- The semantic
analyser checks the meaning of the
program. It checks variable declarations
and scope, whether the program has
entered or left loops, or subroutines, etc.
 The final stage is generating machine
code.
Interpreter

 An interpreter is also a program that


translates a high-level language into a
low-level one, but it does it at the moment
the program is run.
How it is done?
We write the program using a text
editor and then instruct the interpreter to
run the program. It takes the program, one
line at a time, and translates each line
before running it. It translates the first line
and runs it, then translates the second line
and runs it .
When an error is encountered,
the execution of the program is halted and
an error message is displayed.
The interpreter has no "memory"
for the translated lines, so if it comes
across lines of the program within a loop,
it must translate them afresh every time
that particular line runs.
Languages like Assembly Language,
C, C++, Fortran, Pascal were almost
always compiled into machine code.

Languages like Basic,VbScript and


JavaScript were usually interpreted.
Languages that we use now like Java
and C# require no compiling or
interpreting.
Thank You

Potrebbero piacerti anche