3. Compiler and Interpreter
It is important to understand the comparison
between interpreter and compiler as it helps to
understand the working of a program in a better
way.
There are some programming languages like C and
C++ that requires only a compiler whereas some
such as PHP and python requires only an
interpreter.
However, there are some programming languages
such as Java, Haskell and Ocaml which make use
both of compiler and Interpreter.
4. Why Compiler and Interpreter?
The computers understand only binary digits – 1 and 0.
Therefore, we can communicate with the computers only
using 1s and 0s. However, it is very difficult for humans to
communicate using binary digits.
These compiler and interpreter programs help us in
communicating with the computer systems by converting
the high-level language or source code (which is normally
written in English language using C, C++, Java and other
such programming languages) into low-level language or
machine code which consists of only 1 and 0 that is in binary
format.
5. Compiler:
A compiler is a translator program that converts a source
code into an object code. The source code is normally written
in C, C++, etc. and it is translated into a binary format which is
often known as an object code.
A compiler converts the complete source code into object
code at once. It takes the complete program code as its input.
This is one of the most important and basic difference between
compiler and interpreter.
6. The process of translating a source code into machine code
(object code) is faster using a compiler as compared to an interpreter as it
translates the complete source code at once.
A compiler generates errors and warnings only after the compilation process is
completed. It is, therefore, difficult to debug and sort out errors in a program
since the complete source code needs to be checked, unlike an interpreter.
A compiler supports only static memory allocation and does not support
dynamic memory allocation.
The programming languages that use compilation
are C, C++, COBOL, ALGOL, BASIC, Go, Haskell, Java, etc.
7. A compiler performs different tasks such as:
A compiler performs different tasks such as:
Code generation
Code optimization
Semantic analysis
Pre – processing
Parsing
8. There are different types of compilers such
as:
Source – to – source compiler
Just – in – time compiler
Hardware compiler
Byte code compiler
9. Interpreter:
An interpreter takes in only a single statement of instruction as an
input and translates it into object or machine level code. An
interpreter program parses an instruction and executes it’s
immediately.
The interpreted program executes comparatively slower than
compiled program as it checks and interprets every single
statement one by one every time it is executed making it a very
time-consuming process.
However, an interpreter is much more memory efficient than a
compiler since it takes in only a line of instruction as compared to
the complete source code.
10. An interpreter converts the source code line by line into an intermediate
representation and executes its behavior directly.
An interpreter generates errors and warnings line by line, if there are any. It
does not generate an error after interpreting the whole program making it
more user-friendly.
An interpreter, therefore, makes debugging the source code much easier as
it shows the errors line by line.
An interpreter supports dynamic memory allocation and it does not
support static memory allocation.
The programming languages that use interpreters are
BASIC, C, Pascal, Python, PHP, Java, LISP etc.
12. There are different types of
interpreters such as:
Byte code interpreter
Self – interpreter
Abstract syntax tree interpreter
Threaded code interpreter
13. Difference between Compiler and Interpreter
COMPILER INTERPRETER
A compiler translates the
complete source code at once.
A compiler only translates or
converts the source code into
machine code.
The compilation result cannot be
viewed during the course of
translating the source code into
object code.
The process of converting the
source code into machine level
code using a compiler is faster.
Compilation process requires
comparatively more memory as
the object code is generated.
The compiler requires less
time for execution.
An interpreter translates the
source code line by line.
An interpreter directly executes
the given instruction without
compiling them.
The interpreter results can be
viewed at the translation time
since it translates the source
code line by line.
The process of converting the
source code into low-level
machine code is slower.
Interpreters consume less
amount of memory than a
compiler.
An interpreter takes too
much amount of time when
compared to a compiler.
14. COMPILER
A compiler supports a static
allocation of memory.
A compiler, therefore, takes
the complete programs an
input.
An intermediate level code
is generated during
compilation.
The compiler finds and lists
the errors within the
complete program at once.
A compiler generates
intermediate object code
which makes it less
memory efficient.
INTERPRETER
An interpreter
supports dynamic
allocation of memory.
An interpreter takes only
a single instruction as its
input.
No intermediate level code
is not generated during
compilation.
An interpreter finds and
lists the errors after
interpreting every single
statement.
An interpreter does not
generate intermediate
object code making it more
memory efficient.
15. COMPILER INTERPRETER
The compiled code
is difficult to debug.
A compiler does not
support dynamic memory
allocation technique.
Example: PHP, Python,
Ruby, etc.
Programming languages
that support compilation
are C, C++, Java, C#, etc.
Interpretation process
makes it easier to
debug the source code.
An interpreter does not
support static memory
allocation technique.
Example: java, GCC,
clang, go, etc.
Programming languages
that support
interpretation are PHP,
Ruby, .NET, Python,
MATLAB, Perl, BASIC, etc.