You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the three types of translators used to convert programming languages into machine code. This is part of OCR J277 Section 1.5.3.
CPUs can only execute machine code (binary instructions). However, most programmers write code in high-level or assembly languages. A translator is a program that converts source code into machine code so the CPU can execute it.
There are three types of translator:
The following diagram compares how each translator converts source code:
graph LR
SC["High-level\nSource Code"] --> COMP["Compiler"]
SC --> INT["Interpreter"]
ASM["Assembly\nCode"] --> ASMR["Assembler"]
COMP --> EXE["Executable\n(Machine Code)"]
INT --> RUN["Executes line\nby line"]
ASMR --> MC["Machine Code"]
A compiler translates the entire source code of a high-level language program into machine code all at once, before the program is run.
Source code (e.g. Python, C++) → COMPILER → Executable machine code file
| Feature | Detail |
|---|---|
| Translation | Translates the entire program at once |
| Output | Produces a standalone executable file |
| Error reporting | Reports all errors after compilation; program won't compile until all errors are fixed |
| Execution speed | Fast — the executable is already in machine code |
| Distribution | The executable can be distributed without sharing the source code |
| Re-compilation | Any change to the source code requires the entire program to be re-compiled |
An interpreter translates and executes high-level source code one line at a time, as the program runs.
Source code → INTERPRETER → (translates and executes line by line)
| Feature | Detail |
|---|---|
| Translation | Translates and executes one line at a time |
| Output | No standalone executable is produced |
| Error reporting | Stops at the first error found, making debugging easier |
| Execution speed | Slower — must re-translate the code every time the program runs |
| Distribution | Source code must be shared (and the interpreter must be available) |
| Development | Useful for testing and debugging during development |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.