Translators (OCR A Level Computer Science)

Revision Note

Callum Davies

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

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 calculate x 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 that name 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!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Callum Davies

Author: Callum Davies

Expertise: Computer Science

Callum is an experienced teacher of GCSE and A-Level Computer Science. He has 4 years of teaching experience and has detailed knowledge of how to achieve exam success, having marked for OCR A-Level. Callum is now a software engineer and regularly mentors new engineers.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.