Language Translators Computer Science As Level
Language Translators Computer Science As Level
COMPUTING 9608
• 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.
Pascal
C++
Java
Python
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 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
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.
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.
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.
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.
• 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.
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