Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

OOPS - COMPILER INTERPRETER, Study notes of Object Oriented Programming

Detailed informtion about Compiler vs. Interpreter, Compiler characteristics, Interpreter characteristics, advantages, high-level language, Basic program.

Typology: Study notes

2010/2011

Uploaded on 09/04/2011

vrunda
vrunda 🇮🇳

4.1

(21)

76 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
3.1 Compiler vs. Interpreter
An interpreter translates some form of source code into a target representation that it can
immediately execute and evaluate. The structure of the interpreter is similar to that of a
compiler, but the amount of time it takes to produce the executable representation will vary as
will the amount of optimization. The following diagram shows one representation of the
dierences.
Compiler characteristics:
spends a lot of time analyzing and processing the program
the resulting executable is some form of machine- specic binary code
the computer hardware interprets (executes) the resulting code
program execution is fast
Interpreter characteristics:
relatively little time is spent analyzing and processing the program
the resulting code is some sort of intermediate code
the resulting code is interpreted by another program
program execution is relatively slow
The above characteristics are typical. There are well-known cases that are somewhere in
between, such as Java with it's JVM.
Interpreters
An interpreter is also a program that translates a high-level language into a low-
level one, but it does it at the moment the program is run. You write the program
using a text editor or something similar, and then instruct the interpreter to run the
program. It takes the program, one line at a time, and translates each line before
running it: It translates the first line and runs it, then translates the second line and
runs it etc. The interpreter has no "memory" for the translated lines, so if it comes
across lines of the program within a loop, it must translate them afresh every time
that particular line runs. Consider this simple Basic program:
10 FOR COUNT = 1 TO 1000
20 PRINT COUNT * COUNT
30 NEXT COUNT
Line 20 of the program displays the square of the value stored in COUNT and this
line has to be carried out 1000 times. The interpreter must also translate that line
1000 times, which is clearly an inefficient process. However, interpreted languages
do have their uses, as we will see in a later section.
Examples of interpreted languages are Basic, JavaScript and LISP.
Well, that depends on how you want to write and run your program. The main
advantages of compilers are as follows:
pf2

Partial preview of the text

Download OOPS - COMPILER INTERPRETER and more Study notes Object Oriented Programming in PDF only on Docsity!

3.1 Compiler vs. Interpreter An interpreter translates some form of source code into a target representation that it can immediately execute and evaluate. The structure of the interpreter is similar to that of a compiler, but the amount of time it takes to produce the executable representation will vary as will the amount of optimization. The following diagram shows one representation of the differences.

Compiler characteristics:

  • spends a lot of time analyzing and processing the program
  • the resulting executable is some form of machine- specific binary code
  • the computer hardware interprets (executes) the resulting code
  • program execution is fast Interpreter characteristics:
  • relatively little time is spent analyzing and processing the program
  • the resulting code is some sort of intermediate code
  • the resulting code is interpreted by another program
  • program execution is relatively slow The above characteristics are typical. There are well-known cases that are somewhere in between, such as Java with it's JVM.

Interpreters

An interpreter is also a program that translates a high-level language into a low- level one, but it does it at the moment the program is run. You write the program using a text editor or something similar, and then instruct the interpreter to run the program. It takes the program, one line at a time, and translates each line before running it: It translates the first line and runs it, then translates the second line and runs it etc. The interpreter has no "memory" for the translated lines, so if it comes across lines of the program within a loop, it must translate them afresh every time that particular line runs. Consider this simple Basic program: 10 FOR COUNT = 1 TO 1000 20 PRINT COUNT * COUNT 30 NEXT COUNT

Line 20 of the program displays the square of the value stored in COUNT and this

line has to be carried out 1000 times. The interpreter must also translate that line 1000 times, which is clearly an inefficient process. However, interpreted languages do have their uses, as we will see in a later section.

Examples of interpreted languages are Basic, JavaScript and LISP.

Well, that depends on how you want to write and run your program. The main advantages of compilers are as follows:

  • They produce programs which run quickly.
  • They can spot syntax errors while the program is being compiled (i.e. you are informed of any grammatical errors before you try to run the program). However, this does not mean that a program that compiles correctly is error-free!

The main advantages of interpreters are as follows:

  • There is no lengthy "compile time", i.e. you do not have to wait between writing a program and running it, for it to compile. As soon as you have written a program, you can run it.
  • They tend to be more "portable", which means that they will run on a greater variety of machines. This is because each machine can have its own interpreter for that language. For instance, the version of the BASIC interpreter for the PDP series computers is different from the QBasic program for personal computers, as they run on different pieces of hardware, but programs written in BASIC are identical from the user's point of view.