2. An Interpreter is a
Translator
Examples of translators:
● Compilers - translates high level code to low level code, e.g. Java -> JVM
● Assemblers - translates assembly language code to machine code, e.g. x86as -> x86
● High-level translators - translates code from one PL to another, e.g. Java -> C
● Decompilers - translates low-level code to high-level code, e.g. Java JVM bytecode -> Java
3. High Level / Low Level
Low High
Machine Readable Human Readable
Binary: 011011 Grammar: if let, while, for
executable Not executable
Knows about hardware Does not know about hardware
4. A compiler can be compared to taking a foreign
movie and first sub-titling it and then being able to
watch it again and again.
While an interpreter is like having a translator at the
UN translate each line of a delegate’s speech in real-
time.
AKA...
The compiler translates the entire program before it is run.
The interpreters translate a line at a time while the program is being run.
7. Advantages of Compiled Languages
- Pre-Compiled binaries are inherently more difficult to reverse-engineer and
are therefore helpful to closed-source software providers wishing to keep the
I.P. contained in their source code private.
- Once a program is translated into native instructions (machine code), it can
then be executed over and over again withouth the overhead of this
translation.
- Ability to support architectures the interpreter hasn't been compiled for (such
as embedded systems)
- Can be optimized more heavily due to larger window of code to be translated.
8. Advantages of Interpreted Languages
- Programs can immediately be executed without the requirement of compiling
first.
- Potentially has lower memory footprint because no Object Code is created.
- Supports portability if interpreter is installed on different platforms.
- Starts executing immediately (no compilation phase)
- Source Code can be more easily changed between program executions
because there is no compilation step in between.
9. Hybrid Approach
An interpretive compiler combines fast translation with moderately fast execution, provided that:
● VM code is lower than the source language, but higher than native machine code
● VM instructions have simple formats (can be quickly analysed by an interpreter)
Example: JDK provides an interpretive compiler for Java.
11. - any language can be either compiled or interpreted but the implementation of the language is what is either one or both. Sometimes even a
spectrum of compiled/interpreted
- Etymology - compiler (pile things together, throw in pile), interpreter (inter, between source and assembly)
- Interpreted languages require the interpreted to be installed on host machine
- Interpreter continues interpreting until it hits an error
- Compiler will check errors for you at compilation time
- Compiled program requires more memory as all the code is compiled as opposed to line by line discarding the previous line. However with
modern computers equipped with gigabytes of ram this isn’t a practical concern.
Extra Points