0% found this document useful (0 votes)
87 views

Difference Between Compiler and Interpreter

The document discusses the differences between compilers and interpreters. Compilers scan the entire program and translate it into machine code all at once, while interpreters translate programs one statement at a time. Compilers generate error messages only after scanning the whole program, making debugging harder, while interpreters stop at the first error. Programming languages like C/C++ typically use compilers, while languages like Python and Ruby typically use interpreters.

Uploaded by

jrruururr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Difference Between Compiler and Interpreter

The document discusses the differences between compilers and interpreters. Compilers scan the entire program and translate it into machine code all at once, while interpreters translate programs one statement at a time. Compilers generate error messages only after scanning the whole program, making debugging harder, while interpreters stop at the first error. Programming languages like C/C++ typically use compilers, while languages like Python and Ruby typically use interpreters.

Uploaded by

jrruururr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Difference between Compiler and Interpreter:

We generally write a computer program using a high-level language. A high-level language


is one which is understandable by us humans. It contains words and phrases from the
English (or other) language. But a computer does not understand high-level language. It
only understands program written in 0's and 1's in binary, called the machine code. A
program written in high-level language is called a source code. We need to convert the
source code into machine code and this is accomplished my compilers and interpreters.
Hence, a compiler or an interpreter is a program that converts program written in high-level
language into machine code understood by the computer.
The difference between an interpreter and a compiler is given below:
Interpreter

Compiler

Translates program one statement at a time.

Scans the entire program and translates it as a


whole into machine code.

It takes less amount of time to analyze the


source code but the overall execution time is
slower.

It takes large amount of time to analyze the


source code but the overall execution time is
comparatively faster.

No intermediate object code is generated,


hence are memory efficient.

Generates intermediate object code which


further requires linking, hence requires more
memory.

Continues translating the program until the


first error is met, in which case it stops. Hence
debugging is easy.

It generates the error message only after


scanning the whole program. Hence debugging
is comparatively hard.

Programming language like Python, Ruby use


interpreters.

Programming language like C, C++ use


compilers.

Difference between High level and Low level languages:


High Level Language:
1.
2.
3.
4.

High-level languages are easy to learn.


High0level languages are near to human languages.
Programs in high-level languages are slow in execution.
Programs in high-level languages are easy to modify.

5. High-level languages do not provide much facility at hardware level.


6. Knowledge of hardware is not required to write programs.
7. These languages are normally used to write application programs.

Low Level Language:


1.
2.
3.
4.
5.
6.
7.

Low-level languages are difficult to learn.


Low-level languages are far from human languages.
Programs in low-level languages are fast in execution.
Programs in low-level languages are difficult to modify.
Low-level languages provide facility to write programs at hardware level.
Deep knowledge of hardware is required to write programs.
These languages are normally used to write hardware programs

PERL: Perl is a general-purpose programming language originally developed for text manipulation
and now used for a wide range of tasks including system administration, web development, network
programming, GUI development, and more.

What is Perl?

PERL is nothing but Practical Extraction and Report Language.

It is used for mission critical projects in the public and private sectors.

Perl is Open Source software, licensed under its Artistic License

Perl was created by Larry Wall.

Perl 1.0 was released to usenet's alt.comp.sources in 1987

The current version of perl is 5.24.0

Perl Features

Perls database integration interface DBI supports third-party databases including Oracle,
Sybase, Postgres, MySQL and others.

Perl works with HTML, XML, and other mark-up languages.

Perl supports Unicode.

Perl supports both procedural and object-oriented programming.

The Perl interpreter can be embedded into other systems.

Perl used to be the most popular web programming language due to its text manipulation
capabilities and rapid development cycle.

Perl can handle encrypted Web data, including e-commerce transactions.

Perl is interpreted
Perl is an interpreted language, which means that your code can be run as is, without a compilation
stage that creates a non portable executable program.

Traditional compilers convert programs into machine language. When you run a Perl program, it's first
compiled into a byte code, which is then converted ( as the program runs) into machine instructions.

First program
Your first program will look like this:

1. use strict;
2. use warnings;
3. print"Hello World";
Let me explain it step-by-step.
Output: Hello world

1. print"Hello World\n";
As you can see statements in perl end with a semi-colon ;. The \n is the sign we used to denote a
newline. Strings are enclosed in double-quotes ". The print function prints to the screen. When this is
executed perl will print the text and at the end it will print a newline.
Save the file as hello.pl and then you can run the code by selecting terminal . Run as perl hello.pl

User Input
Now let's improve our example by asking the user her name and including it in the response.

1. use5.010;
2. use strict;
3. use warnings;
4.
5. say "What is your name? ";
6. my $name =<STDIN>;
7. say "Hello $name, how are you?";
$name is called a scalar variable.

Scalar: A scalar is a single unit of data. That data might be an integer number, floating point, a
character, a string, a paragraph, or an entire web page.
Variables are declared using the my keyword. (actually that's one of the requirements strict adds.)
Scalar variables always start with a $ sign. The <STDIN> is the tool to read a line from the keyboard.
It will ask for your name. Type in your name and press ENTER to let perl know you have finished
typing in your name.

You will notice that the output is a bit broken: The comma after the name appears on a newline. That's
because the ENTER you pressed, when typing in your name, got into the $name variable.
Getting rid of newlines

1. use5.010;
2. use strict;
3. use warnings;
4.
5. say "What is your name? ";
6. my $name =<STDIN>;
7. chomp $name;
8. say "Hello $name, how are you?";
It is such a common task in Perl, that there is a special function called chomp to remove the trailing
newlines from strings.

Conclusion
In every script you write you should always add use strict; and use warnings; as the first two statements.
It is also very recommended to add use 5.010;.

Exercises
1. use strict;
2. use warnings;
3. use5.010;
4. say "Hello ";
5. say "World";
It did not show on one line. Why? How to fix it?

Exercise 2
Write a script that asks the user for two numbers, one after the other. Then prints out the sum of the two
numbers.

You might also like