0% found this document useful (0 votes)
55 views6 pages

1.6 Compiler and Interpreter

The document explains the differences between compilers and interpreters, which are both used to convert high-level programming languages into machine code. A compiler translates the entire source code at once and generates an executable file, while an interpreter translates code line-by-line during execution. Each has its advantages and disadvantages, such as execution speed and error handling, with compilers being faster but less flexible, and interpreters being easier for debugging but slower overall.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views6 pages

1.6 Compiler and Interpreter

The document explains the differences between compilers and interpreters, which are both used to convert high-level programming languages into machine code. A compiler translates the entire source code at once and generates an executable file, while an interpreter translates code line-by-line during execution. Each has its advantages and disadvantages, such as execution speed and error handling, with compilers being faster but less flexible, and interpreters being easier for debugging but slower overall.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Difference between Compiler and Interpreter

We mostly write a computer program in high-level languages, which humans


understand. High-level languages are that which contains words and phrases
from human languages - for example, English. The high-level programming
language is also known as source code in a computer program. However,
computer machine does not understand these high-level programming
languages. It only understood its machine code, i.e., a program
in 0's and 1's in binary form to perform the task accordingly.

To perform an instruction written in high-level language via computer, we


need to convert it into machine language. To do this, either a compiler or
an interpreter, or both are used to convert a source code programming
language into machine code. Compiler and interpreter are software
programs that convert a high-level language into a machine language (0's
and 1's binary form) that a computer can understand and perform tasks as
per the program's instructions. But there are variations in the working
process and steps of a compiler and interpreter. Before diving into the
difference between a compiler and an interpreter, let's see a brief
introduction about both of them.

Compiler
A compiler

is a software program that follows the syntax rule of programming language to convert a source code to
machine code. It cannot fix any error if present in a program; it generates an error message, and you
have to correct it yourself in the program's syntax. If your written program is correct (contains no error),
then the compiler will convert your entire source code into machine code. A compiler converts
complete source code into machine code at once. And finally, your program get executes.
The entire compilation steps of source code are operated into two
phases: Analysis Phase and Synthesis Phase.

o Analysis Phase: This compiler phase is also known as the front end phase in
which a source code is divided into fundamental parts to check grammar,
syntax, and semantic of code; after that, the intermediate code is generated.
The analysis phase of the compilation process includes a lexical analyzer,
semantic analyzer, and syntax analyzer.
o Synthesis Phase: The Synthesis phase is also known as the back end phase
in which the intermediate code (which was generated in Analysis Phase) is
optimized and generated into target machine code. The synthesis phase of
the compilation process includes code optimizer and code generator tasks.

Interpreter
An interpreter

is also a software program that translates a source code into a machine language. However, an
interpreter converts high-level programming language into machine language line-by-line while
interpreting and running the program.
Difference between Compiler and Interpreter
Difference Compiler Interpreter
Types
Programmi
o Write a program in o Write a program in
ng Steps
source code. source code.
o Compile will analyze o No linking of files
your program happens, or no
statements and check machine code will
their correctness. If an generate separately.
error is found in a o The source code
program, it throws an programming
error message. statements are
o If the program executed line-by-line
contains no error, during their execution.
then the compiler will If an error is found at
convert the source any specific statement
code program into interpreter, it stops
machine code. further execution until
o The compiler links all the error gets removed.
the code files into a
single runnable
program, which is
known as the exe file.
o Finally, it runs the
program and
generates output.

Translation A compiler translates An interpreter translates one


type complete high-level statement of programming
programming code into code at a time into machine
machine code at once. code.

Advantage As the source code is As the source code is


already converted into interpreted line-by-line, error
machine code, the code detection and correction
execution time becomes become easy.
short.

Disadvanta If you want to change your Interpreted programs can run


ge program for any reason, on only those computers
either by error or logical which have the same
changes, you can do it only interpreter.
by going back to your
source code.

Machine It stores the converted It never stores the machine


code machine code from your code at all on the disk.
source code program on the
disk.

Running A compiler takes an An interpreter takes less time


time enormous time to analyze to analyze source code as
source code. However, compared to a compiler.
overall compiled However, overall interpreted
programming code runs programming code runs
faster as compression to an slower as compression to the
interpreter. compiler.

Program The compiler generates an The interpreter doesn't


generation output of a program (in the generate a separate machine
form of an exe file) that can code as an output program.
run separately from the So it checks the source code
source code program. every time during the
execution.

Execution The process of program The process of program


execution takes place execution is a part of
separately from its interpretation steps, so it is
compilation process. done line-by-line
Program execution only simultaneously.
takes place after the
complete program is
compiled.

Memory A compiled program is An interpreted program does


requireme generated into an not generate an intermediate
nt intermediate object code, code. So there is no
and it further required requirement for extra
linking. So there is a memory.
requirement for more
memory.
Best suited The compiled program is In web environments,
for bounded to the specific compiling takes place
target machine. It requires relatively more time to run
the same compiler on the even small code, which may
machine to execute; C and not run multiple times. As
C++ are the most popular load time is essential in the
programming language web environment,
based on the compilation interpreters are better.
model. JavaScript, Python, Ruby are
based on the interpreter
model.

Error The compiler shows the An interpreter reads the


execution complete errors and program line-by-line; it shows
warning messages at the error if present at that
program compilation time. specific line. You must have
So it is not possible to run to correct the error first to
the program without fixing interpret the next line of the
program errors. Doing program. Debugging is
debugging of the program is comparatively easy while
comparatively complex working with an Interpreter.
while working with a
compiler.

Advantage and disadvantage of compiler


While using a compiler to translate a source code into machine code, the
program codes are translated into different object codes. Hence the time of
code execution is significantly less. The drawback of using a compiler is that
you can only make changes in the program by going back to your source
code.

Advantage and disadvantage of an interpreter


The interpreter makes it easier to work with source code. So it is highly
preferred, especially for beginners. Interpreted programs can run on only
those computers which have the same interpreter.

You might also like