Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
194 views

Language Translators Computer Science As Level

High level programming languages are easier for humans to read and write than low level machine languages. They use symbolic notation resembling English and are portable between machines. Compilers translate entire high level programs into machine code for execution, while interpreters translate and execute code line-by-line. Java blurs the distinction by compiling to bytecode then interpreting with a JVM, with modern JVMs using just-in-time compilation to native code for improved performance.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
194 views

Language Translators Computer Science As Level

High level programming languages are easier for humans to read and write than low level machine languages. They use symbolic notation resembling English and are portable between machines. Compilers translate entire high level programs into machine code for execution, while interpreters translate and execute code line-by-line. Java blurs the distinction by compiling to bytecode then interpreting with a JVM, with modern JVMs using just-in-time compilation to native code for improved performance.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1

COMPUTING 9608

COMPILERS AND INTEPREPTERS


HIGH LEVEL LANGUAGES
Low level languages are close to the native language of the processor. High level languages
are closer to the native language of the user e.g. English. You are familiar with the low level
languages machine code and Assembly languages. This handout deals with high level
languages. The following are the characteristics of any high level language:

• High level languages resemble the native language of the user e.g. English.
• High level languages are largely symbolic – they use English language, for example,
and mathematical symbols.
• High level languages are problem-oriented.
• Whereas low level languages are machine specific and therefore not portable, high
level languages are not machine specific and are therefore portable.

Examples of high level languages:


 VISUAL BASIC (Beginners All Purpose Symbolic Instruction Code).

 FORTRAN (Formula Translation).

 ALGOL (Algorithmic Language).

 APL (A Programming Language).

 Pascal

 C++

 COBOL (Common Business Oriented Language).

 Java

 Python

Advantages of high level languages


 User-friendly

 Similar to English with vocabulary of words and symbols

 Therefore it is easier to learn.

 They require less time to write.


2

 They are easier to maintain.

 Problem oriented rather than 'machine' based.

 Program written in a high-level language can be translated into many machine


languages and therefore can run on any computer for which there exists an
appropriate translator.

• It is independent of the machine on which it is used i.e. Programs developed in a


high level language can be run on any Computer. It is portable

Disadvantages of high level languages

• A high-level language has to be translated into the machine language by a translator


and thus a price in computer time is paid – runs slowly.

• The machine code generated by a translator might be inefficient compared to an


equivalent assembly language program.

TRANSLATORS: COMPILERS AND INTEPRETERS


Unfortunately, a computer cannot understand a high level language. High languages need to
be translated into machine code for the processors to recognise. Compilers and
Interpreters are programs that can convert a high level language into machine code.

COMPILER
A compiler translates a whole program in a high-level language (the source code) into
machine code (the object code). The machine code version of the program is called an
executable file.

Note:

 the source program will not be compiled if it has any errors.

 The whole program in a high level program is translated into machine code.

 Once a program has been compiled it can be loaded into the machine without any
further need for a compiler.

The original high level language is called the source code and the final compiled version is
called the object code. The object code is the executable file.
3

ADVANTAGES OF A COMPILER

 The executable file can be distributed to many users

 Once compiled the compiler software is no longer needed.

 Users have no sight of the source code so they cannot alter it.

DISADVANTAGES OF A COMPILER

 The object code can only be produced when all errors in the source code have been
located and corrected.

 The development process can be time-consuming as it may need to be run several


times to debug and correct all the errors.

 A compiler uses a lot of the computer’s resources.

- During compilation the memory stores

The compiler software

The source code

The object code

Working storage used while the translation is taking place.

 A compiler reads the whole source code and translates it into a complete machine
code program to perform the required tasks which is output as a new file. This
completely separates the source code from the executable file. The translation is
done once only and as a separate process.

 Hence you cannot change the compiled program without going back to the original
source code.

PORTABILITY OF A COMPILER

• A compiler program is written for each software and hardware processor separately.

• Therefore a compiler is not portable.


4

INTERPRETER
A compiler takes all of the code and translates it into something a computer can
understand. This compiled code is then executed or saved to a file to be executed at a later
time.

An interpreter takes code and translates it instruction by instruction, in sequence, and


doesn't save the translated code in a file.

A programmer can try to run a program as soon as some of the source code has been
written. Translation happens on the fly which is followed by immediate execution. The
interpreter identifies each instruction in sequence and executes it until it encounters an
error. On encountering an error the program terminates and the error is pinpointed to the
programmer.

ADVANTAGES OF AN INTERPRETER
 The programmer can attempt to run the program at any time, even before all the
code has been written.

 Errors are reported immediately.

 Debugging is easier and faster.

• An interpreter is portable

DISADVANTAGES OF AN INTERPRETER

An interpreter reads the source code one instruction or line at a time, converts this line into
machine code and executes it. The machine code is then discarded and the next line is read.

 Every instruction has to be translated every time it is executed, even if it is executed


many times as the program runs, including instructions in loops.

 Because of this interpreters tend to be slow.

 The interpreter software has to be present in memory every time an attempt is


made to run the program.
5

THE BEST OF BOTH WORLDS


 Early versions of BASIC had both an interpreter and a compiler.

 A programmer could use the interpreter during program development, fixing errors.

 The programmer could then compile the program into an executable file when the
program is working properly.

JAVA
Java programming language is compiled into standard machine language Bytecode, and
then executed by Java Virtual Machine (JVM), software interpreter. Java programming
language can run on any machine that has JVM interpreter; therefore, in order to
increase portability of Java first it is compiled into Bytecode and then interpreted by JVM
interpreter.

Typical Java environment consists of two programs: Java compiler and Java Virtual Machine.
Java compiler takes the source code written in Java programming language, together with
precompiled libraries, and compiles programs written in Java programming languages into
class files containing Java byte code.

The Java Virtual Machine takes the byte code prepared by the Java compiler and executes it.
The byte-code itself is platform-independent, it the responsibility of the Java Virtual
Machine implementation to execute the program in the bytecode form on the real
computer.

The two-staged process blurs the difference between compiled and interpreted language -
typically, Java both compiles the program from human-readable representation into some
machine instructions, but the machine instructions belongs to some abstract architecture
and require interpreter to run on the real computer.

Now, interpreting bytecode instructions one-by-one is straightforward, but slow way to implement
JVM. Modern JVMs internally translate part of the bytecode into a native CPU instructions and then
execute the generated native code; as the process of bytecode translation happens transparently
inside the JVM, it is called Just-In-Time translation, abbreviated to JIT.

Please, note that the similar technology may be implemented by the language environment that
appear to be pure interpreter: pieces of code may be transparently compiled into a byte code or
native code, like with Java JIT - Javascript comes to mind.

END OF HANDOUT

You might also like