Translators (OCR A Level Computer Science)
Revision Note
Written by: Callum Davies
Reviewed by: James Woodhouse
Translators
What is a Translator?
Translators convert source code from a high-level language to a low-level language
There are three main types of translators
Interpreters
Compilers
Assemblers
Interpreters
Interpret source code line-by-line and executes it on the fly
Easier to debug, allows incremental testing, and is generally faster to start execution
Slower execution time overall and requires the interpreter to be present during the execution
Compilers
Translates the entire source code into machine code at once and then executes it
Faster execution time, no need for the compiler during execution
Longer initial compilation time and can be more challenging to debug
Assemblers
Assemblers translate assembly language into machine code
Unlike interpreters and compilers that work with high-level languages, assemblers deal with low-level languages
The diagram below shows examples of programming languages, from low-level to high-level
Levels of Abstraction in Programming Languages
Translators used for common languages
Programming Language | Translator |
---|---|
C | Compiler |
C++ | Compiler |
Java | Compiler |
Python | Interpreter |
JavaScript | Interpreter |
Ruby | Interpreter |
Swift | Compiler |
Assembly Language | Assembler |
PHP | Interpreter |
Why do different languages have different translators? (non-syllabus content)
Level of Abstraction
High-level languages like Python or JavaScript are further from machine language and often use interpreters to allow more flexibility and ease of development
Low-level languages like C or Assembly are closer to machine code and typically use compilers or assemblers for efficiency
Execution Model
Languages like C and C++ are compiled into machine code specific to a target platform
This allows for optimisations to make the code run more efficiently
But the code is generally not portable between different platforms
Languages like Python and JavaScript are interpreted, meaning they are translated line-by-line at runtime on any platform
This provides greater portability, as the same code can run on different platforms
This may sacrifice some performance compared to compiled code
Development Paradigm
Interpreted languages allow determining variable types at runtime, which makes development faster
e.g.
var x = 5
(Interpreter will calculatex
to be a number at runtime)
Compiled languages enforce stricter type-checking at compile time, which requires additional work across the project
e.g.
String var name = 'Michael';
(Compiler will demand thatname
has a data type before compiling)
Worked Example
The program below is written in assembly code using the Little Man Computer instruction set. It is supposed to take in two numbers and output the higher.
INP
STA NUMA
INP
STA NUMB
SUB NUMA
BRP NOTA
LDA NUMB
BRA QUIT
NOTA LDA NUMA
QUIT OUT
HLT
NUMA DAT
NUMB DAT
State what type of translator program would be needed to convert the code above into machine code.
[1]
Answer:
Answer that gets full marks:
Assembler.
Last updated:
You've read 0 of your 10 free revision notes
Unlock more, it's free!
Did this page help you?