Translators (SQA National 5 Computing Science): Revision Note

Exam code: X816 75

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

Translators

What is a translator?

  • A translator is a program that converts source code written in a programming language into machine code so that it can be executed by a computer’s processor

  • There are two main types of translator:

    • Compiler – translates all the source code into machine code at once, producing an executable file

    • Interpreter – translates and executes the program one line at a time

Translator

How it works

When it’s used

Notes

Compiler

Translates the whole program into machine code before running

Used when a program is complete and ready to be distributed

Creates an executable file

Interpreter

Translates and runs one line of code at a time

Used during program development and testing

Easier to find and fix errors

  • Key points:

    • A compiler must recompile the program each time it changes

    • An interpreter stops when it finds an error

    • Both translate high-level languages (e.g. Python, Java, C++)

Worked Example

A programmer has written a fixed loop to calculate the total duration of 10 songs for a playlist:

REPEAT 10 TIMES
    RECEIVE songDuration FROM KEYBOARD
    SET totalDuration TO totalDuration + songDuration
END REPEAT

Explain the difference in how a Compiler and an Interpreter would translate the lines of code inside the loop (RECEIVE and SET) during the execution process.

[4]

Answer

  • Compiler:

    • Translates the full code (including the loop) once [1 mark]

    • Before execution begins [1 mark]

  • Interpreter:

    • Translates the code line by line [1 mark]

    • Repeatedly (for every iteration of the loop) during execution [1 mark]

Unlock more, it's free!

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

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

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.