You are on page 1of 17

COMPILER AND INTERPRETER

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.
•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.
•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
PYTHON IS INTERPRETED OR
COMPILER?
IN VARIOUS BOOKS OF PYTHON PROGRAMMING, IT IS MENTIONED THAT PYTHON LANGUAGE IS
INTERPRETED. BUT THAT IS HALF CORRECT THE PYTHON PROGRAM IS FIRST COMPILED AND THEN
INTERPRETED. THE COMPILATION PART IS HIDDEN FROM THE PROGRAMMER THUS, MANY
PROGRAMMERS BELIEVE THAT IT IS AN INTERPRETED LANGUAGE. THE COMPILATION PART IS DONE
FIRST WHEN WE EXECUTE OUR CODE AND THIS WILL GENERATE BYTE CODE AND INTERNALLY THIS
BYTE CODE GETS CONVERTED BY THE PYTHON VIRTUAL MACHINE(P.V.M) ACCORDING TO THE
UNDERLYING PLATFORM(MACHINE+OPERATING SYSTEM).
NOW THE QUESTION IS – IF THERE IS ANY PROOF THAT PYTHON FIRST COMPILES THE PROGRAM
INTERNALLY AND THEN RUN THE CODE VIA INTERPRETER?
THE ANSWER IS YES! AND NOTE THIS COMPILED PART IS GET DELETED BY THE PYTHON(AS SOON AS
YOU EXECUTE YOUR CODE) JUST IT DOES NOT WANT PROGRAMMERS TO GET INTO COMPLEXITY.
ADVANTAGES OF COMPILER
 Improved performance: Compiled code tends to run faster than interpreted
code because it has been translated into machine code that can be directly
executed by the computer’s processor. This can be particularly important
for performance-critical applications, such as scientific simulations or real-
time systems.
 Portability: Compilers allow programmers to write code in a high-level
programming language that can be easily translated into machine code for
a variety of different platforms. This makes it easier to develop software
that can run on different systems without requiring significant changes to
the source code.
ADVANTAGES OF COMPILER
 Debugging support: Most compilers include a number of debugging tools
that can help programmers find and fix errors in their code. These tools can
include features such as syntax highlighting, error messages, and
debuggers that allow programmers to step through their code line by line.
 Increased Security: Compilers can help improve the security of software by
performing a number of checks on the source code, such as checking for
syntax errors and enforcing type safety. This can help prevent certain types
of vulnerabilities, such as buffer overflows and type coercion attacks.
DISADVANTAGES OF COMPILER
 Compilation time: Depending on the size and complexity of the source code,
compilation can take a significant amount of time. This can be a hindrance to
productivity if frequent updates to the code are required.
 Error detection: Compilers can only detect syntax errors and certain semantic
errors, and may not catch all errors in the source code. This means that the
compiled program may not behave as expected, and debugging may be
required to identify and fix the errors.
 Portability: Programs compiled for a specific platform or architecture may not
be able to run on other platforms or architectures without being recompiled.
This can be a limitation if the program needs to be run on multiple platforms.
 Execution speed: Programs compiled from high-level languages may not be as
fast as programs written in low-level languages, as the compiled code may
include additional instructions for the compiler to interpret.
ADVANTAGES AND
DISADVANTAGES OF
INTERPRETER
ADVANTAGES OF INTERPRETER
 Advantage of interpreter is that it is executed line by line which helps
users to find errors easily.
 Portability: Programs written in interpreted languages can be run on any
platform that has the interpreter installed, without needing to be recompiled
for each platform.
 Debugging: Debugging programs written in interpreted languages is often
easier, as the interpreter can provide real-time feedback on errors in the
code, allowing developers to fix issues quickly and efficiently.
 Rapid development: Interpreted languages can often be developed more
quickly than compiled languages, as changes can be made to the code
and tested immediately, without the need for a lengthy compilation process.
ADVANTAGES OF INTERPRETER
 Flexibility: Interpreted languages tend to be more flexible than compiled
languages, as they can be dynamically typed and allow for more rapid
prototyping.
 Interactive mode: Many interpreters offer an interactive mode that allows
users to enter commands and see the output immediately, which can be
helpful for experimenting and learning.
 Memory management: Interpreters often handle memory management
automatically, which can simplify programming and reduce the risk of
memory-related errors.
DISADVANTAGES OF
INTERPRETER
 Disadvantage of interpreter is that it takes more time to execute
successfully than compiler.
 Interpreters provide a faster development cycle because they can execute
code line-by-line, allowing developers to test and debug their code in real-
time.
 Interpreters are platform-independent, meaning that code written in a high-
level language can be executed on any machine that has the interpreter
installed.
 Interpreters make it easier to write interactive code because they can
execute user input in real-time, allowing for immediate feedback.
DISADVANTAGES OF COMPILER
 Interpreters are better suited for scripting languages because they
allow for quick prototyping and rapid development of small programs.
 Interpreters typically have a smaller memory footprint than compiled
programs, making them more suitable for low-resource environments.
 Interpreters are easier to use than compilers because they do not
require a separate compilation step.
 Interpreters provide better error reporting than compilers because they
can report errors on a line-by-line basis, making it easier to pinpoint
and correct errors in the code.

You might also like