Logo

dev-resources.site

for different kinds of informations.

Introduction to Programming - Compiler and Interpreter

Published at
5/8/2022
Categories
introtoprogramming
beginners
compilers
interpreters
Author
dchhitarka
Author
10 person written this
dchhitarka
open
Introduction to Programming - Compiler and Interpreter

We have talked about what is programming, and we have also talked about different programming paradigms and some of the languages which follow those paradigms. Now, let us talk about how these programs are executed by the computer.

In the article Introduction to programming — What is programming?, I briefly explained that Programming languages are used to write code which is then translated into machine-level code which is understood by the computer. This translation is done with the help of tools such as compilers or interpreters.

Some languages use compilers while others use interprets for this task. Based on this, languages are often termed as compiled language and interpreted language. Let us discuss these both in detail.

COMPILER

A compiler is a translator that takes a high-level programming language such as Java as input and produces an output of low-level language (like an assembly or machine language).

It is basically a computer program used to transform codes written in a programming language into machine code (human-readable code to a binary 0 and 1 bits language for a computer processor to understand).

The computer then processes the machine code for performing the corresponding tasks.

The compiler takes the whole code, checks all types of errors, limits, and ranges, and compiles it into machine code which is then executed by the computer. If any changes are made to the code, then the whole code needs to be re-compiled only then will the changes reflect.

Note: The time required by the compiler to compile the code is called compile-time where as the time used while executing the code is termed as run-time.

In case of compiled languages, compile-time is relative longer while the run-time is shorter as the code is already translated into machine-level code and the computer just need to run that code.

Compiler stores the translated machine code and execute it every time the code is run. So, it requires more memory.

Java, C++, C#, Go etc., are some of the most widely used high-level programming languages using compiler for translation of their code to machine level code.

Compiled languages often termed as statically typed programming languages as Compilers are very difficult to implement because they can’t predict anything that happens during the turn time.

INTERPRETER

Interpreter is a program that functions for the translation of a programming language into a comprehensible one. It is a computer program used for converting high-level program statements into machine codes. It includes pre-compiled code, source code, and scripts.

Interpreter is similar to compiler as it also translates high-level programming languages into machine code but the difference is that unlike compiler, interpreter reads the code line by line, check for any error in that line and then convert that line or statement to machine code.

Interpreter does not store the machine level code, so it takes less memory but since the code is not stored, it is generated every time the code is run.

Also, since code is not compiled, it has no compile-time, but it’s run-time is very large compared to compiler as every time it converts the high-level programming language code into machine level code line by line or statement by statement.

We will not be able to find all the errors in our code at a time, as the interpreter will stop interpreting the code at the line where it finds any error. Until that error is not fixed, it will not move past that line.

Python, PHP, JavaScript, Ruby etc., are some of the most widely used high-level programming languages using interpreter for translation of their code to machine level code.

These languages are often called as dynamically typed languages as they support Dynamic Typing as interpreter executes code line by line, so at run time, it dynamically determines the type of variables used.

One major advantage of interpreter is that you can run just a single line of code and see it’s output where as in case of compiler you need to first compile the whole code and then run it.

If you liked the article, then please give it a thumb-up.

Read other articles of the series Introduction to programming

interpreters Article's
30 articles in total
Favicon
Matanuska ADR 010 - Architecture, Revisited
Favicon
Matanuska ADR 009 - Type Awareness in The Compiler and Runtime
Favicon
Matanuska ADR 007 - Type Semantics for Primary Types
Favicon
Matanuska ADR 006 - Runtime Exit
Favicon
Matanuska ADR 002 - Architecture
Favicon
Matanuska ADR 003 - Recursive Descent Parser
Favicon
I'm Publishing Matanuska BASIC's ADRs
Favicon
Matanuska ADR 008 - Sigils
Favicon
Matanuska ADR 005 - Editor Operations
Favicon
Matanuska ADR 001 - Encoding Language
Favicon
Pratt Parsing in MiniScript
Favicon
Understanding Interpreters and Compilers in Programming
Favicon
Create Your Own Programming Language 9: Iteration
Favicon
Crafting Interpreters
Favicon
Create Your Own Programming Language 8: Conditionals
Favicon
Create Your Own Programming Language 7: More Types
Favicon
Create Your Own Programming Language 6: Functions
Favicon
Create Your Own Programming Language 4: Variables and Types
Favicon
Create Your Own Programming Language 3: Call Expressions
Favicon
How To Create Your Own Programming Language
Favicon
Create Your Own Programming Language 1: Numbers
Favicon
On What Lexers Do
Favicon
Starting the journey about creating a new programming language
Favicon
Designing and scoping my programming language Lithia
Favicon
Introduction to Programming - Compiler and Interpreter
Favicon
The Feral Programming Language
Favicon
The First Two Weeks: A Compiler Writing Journey
Favicon
Learning Compilers & Interpreters
Favicon
A Most Perfect Union: Just-In-Time Compilers
Favicon
A Deeper Inspection Into Compilation And Interpretation

Featured ones: