Sei sulla pagina 1di 6

A compiler searches all the errors of a program and lists them.

If the program is
error free then it converts the code of program into machine code and then the
program can be executed by separate commands. An interpreter checks the errors
of a program statement by statement.

Computer programs are compiled or interpreted. Languages like Assembly


Language, C, C++, Fortran, Pascal were almost always compiled into machine
code. Languages like Basic,VbScript and JavaScript were usually interpreted.

So what is the difference between a compiled program and an Interpreted


one?

Compiling

Example : C Compiler

To write a program takes these steps:

1.Edit the Program


2.Compile the program into Machine
code files.
3.Link the Machine code files into a
runnable program (also known as an
exe).
4.Debug or Run the Program
With some languages like Turbo
Pascal and Delphi steps 2 and 3 are
combined

Interpreting
Example : BASIC

The steps to run a program via an interpreter are :

1. Edit the Program


2. Debug or Run the Program
3. This is a far faster process and it helps novice programmers edit and test their
code quicker than using a compiler. The disadvantage is that interpreted programs
run much slower than compiled programs. As much as 5-10 times slower as every
line of code has to be re-read, then re-processed.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@
Examples of programming languages that use interpreters: BASIC, Visual Basic,
Python, Ruby, PHP, Perl, MATLAB, Lisp
Examples of programming languages that use compilers: C, C++, COBOL

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2

Difference between Compiler and Interpreter


Learn the main differences between compiler and interpreter. This article tells you
how source code converts into machine code and bytecode. Both compiler and
interpreter take a different approach for this conversion.
What is a Compiler?

First of all you need to understand that computers and humans speak different languages. While
humans speak languages like English, French, Hindi, Spanish, Chinese, Japanese, Arabic etc.;
computers speak only one language i.e. binary. Alphabet of computers contains only two letters,
namely zero and one. Computers are machines and for them it is much easier to work using a
simpler encoding of 0s and 1s.
We humans feel most comfortable if we could issue instructions by writing plain English or
Hindi programs for computers.
The problem is that we are not comfortable with binary and computers find our languages too
difficult to understand. To get around this problem a middle path of an intermediate language is
used to convey human commands to the computers. This intermediate language is called the
programming language.
Programming language is not plain English. It is essentially a predefined syntax of writing
logical computer instructions which humans can also understand.

We also need something to convert programming language into binary language for the
consumption by computer. This is where compiler comes in scene.
Compiler is a software that checks a computer program (called source code) and lists all the
errors found. When humans remove all these errors, compiler converts the program into binary
code (also known as machine code or object code). Computers can understand binary code and
therefore they can execute instructions written by humans using programming language.

Source code and assembly code.


The following video will further help you in understanding the concept and working of a
compiler:

Compiler vs. Interpreter

Now we already know what a compiler does. Task of interpreter is also more or less the same but
interpreter works in a different fashion. The difference between the functioning of compiler and
interpreter will be clear from the table of comparison given below:
#

Compiler

Compiler works on the complete


1 program at once. It takes the entire
program as input.

Interpreter
Interpreter program works line-by-line. It
takes one statement at a time as
input.

2 Compiler generates intermediate code, Interpreter does not generate


called the object code or machine
intermediate object code or machine

code.

code.

Compiler executes conditional control


statements (like if-else and switch3
case) and logical constructs faster
than interpreter.

Interpreter execute conditional control


statements at a much slower speed.

Compiled programs take more


4 memory because the entire object
code has to reside in memory.

Interpreter does not generate


intermediate object code. As a result,
interpreted programs are more
memory efficient.

Compile once and run anytime.


Interpreted programs are interpreted
5 Compiled program does not need to be
line-by-line every time they are run.
compiled every time.
Errors are reported after the entire
6 program is checked for syntactical
and other errors.

Error is reported as soon as the first


error is encountered. Rest of the
program will not be checked until the
existing error is removed.

Debugging is easy because interpreter


A compiled language is more difficult to
stops and reports errors as it encounters
debug.
them.

Compiler does not allow a program to


run until it is completely error-free.

Interpreter runs the program from first


line and stops execution only if it
encounters an error.

Interpreted languages are less efficient


Compiled languages are more efficient but easier to debug. This makes such
9
but difficult to debug.
languages an ideal choice for new
students.
Examples of programming languages
1 Examples of programming languages that use interpreters: BASIC, Visual
0 that use compilers: C, C++, COBOL
Basic, Python, Ruby, PHP, Perl, MATLAB,
Lisp

Following image shows how different languages are either compiled or interpreted:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Java is Both a Compiled and Interpreted Language
Ah! Java is an amazing programming language. Designed originally by James
Gosling, this language encompass several innovative features. One of such features
is Java Virtual Machine (JVM). Also, Java is both a compiled and interpreted
language. When you write a Java program, the javac compiler converts your
program into something called bytecode. All the Java programs run inside a JVM
(this is the secret behind Java being cross-platform language). Bytecode compiled
by javac, enters into JVM memory and there it is interpreted by another program
called java. This java program interprets bytecode line-by-line and converts it into
machine code to be run by the JVM. Following flowchart shows how a Java program
executes.

hope this article helped you in understanding the concepts of compiler and
interpreter. If you have any further questions on the difference between compiler
and interpreter, please feel free to comment and ask me. I will most certainly try to
assist you. Thank you for using TechWelkin!

Potrebbero piacerti anche