High and low-level languages, compilers and interpreters
Processors only understand machine code, but people write programs in languages that are much easier to read. Translators bridge the gap, and choosing between a compiler and an interpreter is a common exam question.
Part 1 of 3: Learn it
In short
- High-level languages are close to English and work on any processor; low-level languages are tied to one type of processor.
- A compiler translates the whole program at once into an executable file.
- An interpreter translates and runs the program one line at a time.
Where this is in your specification
Spec points: AQA 3.4.4, OCR 2.5.1 and 2.5.2, Edexcel Topic 3
| Board | Topic: Languages and translators |
|---|---|
| AQA 8525 | 3.4.4 |
| Edexcel 1CP2 | Topic 3 (programming languages and translators) |
| OCR J277 | 2.5.1 and 2.5.2 |
| Eduqas C500 | 9 Software development |
| Cambridge IGCSE 0478 | 4.2 |
| National 5 C816 75 | Computer systems: translators |
Levels of language
| High-level | Low-level | |
|---|---|---|
| Examples | Python, Java, C# | assembly language, machine code |
| Readability | easy for people to read and write | hard: binary or short mnemonics |
| Processor | portable across processors | written for one processor family |
| Use | most software | device drivers, embedded systems, code that must be very fast or small |
Machine code is binary instructions the CPU runs directly. Assembly uses mnemonics such as LDA and ADD, with one assembly instruction for each machine code instruction.
The three translators
| Compiler | Interpreter | Assembler | |
|---|---|---|---|
| Translates | high-level, whole program | high-level, line by line | assembly into machine code |
| Output | an executable file | no executable: runs straight away | machine code |
| Errors | reported for the whole program after compiling | stops at the first error it reaches | reported after assembling |
| Running | fast, with no translator needed afterwards | slower; the interpreter is needed every time | fast |
Integrated development environments (OCR)
- An editor with features such as auto-indent, syntax highlighting and auto-complete.
- Error diagnostics that point to the line with a problem.
- A run-time environment to test the program, with breakpoints and stepping through code.
- A built-in translator.
Which translator turns assembly language into machine code?
Show the answer
An assembler.
Part 2 of 3: See it worked
Worked examples
Example 1
A games company is about to sell a finished game. Should it give customers compiled or interpreted code? Give two reasons.
- A compiled executable runs without the customer needing a translator
- It usually runs faster
- Customers cannot easily read or copy the original source code
Answer: Compiled: it runs faster, needs no translator, and keeps the source code private.
Example 2
A student is writing and testing a program. Why might an interpreter be useful at this stage?
- An interpreter runs the code line by line
- It stops at the first error and shows where it is
- The student can fix it and run again without waiting for a full compile
Answer: Errors are found and pointed out one at a time, which makes testing and debugging quicker.
Common mistakes
- Saying a compiler runs the program line by line.
- Saying an interpreter produces an executable file.
- Calling assembly language high-level.
- Saying low-level code is always better. It is faster and smaller, but much slower to write and not portable.
Give one disadvantage of an interpreter.
Show the answer
The program runs more slowly, and the interpreter is needed every time it runs.
Part 3 of 3: Test yourself
Check yourself
Answer each one in your head or on paper first, then open it to check.
Which translator turns assembly language into machine code?
An assembler.
Give one disadvantage of an interpreter.
The program runs more slowly, and the interpreter is needed every time it runs.
Why is high-level code described as portable?
It can be translated to run on different types of processor.
Jobs that use this
- Software developer (opens a new tab)
- Computer games developer (opens a new tab)
- Web developer (opens a new tab)
Each link opens the job profile on the National Careers Service (England). In the rest of the UK: My World of Work (Scotland), Careers Wales, nidirect careers (Northern Ireland).
Full lessons and marked practice for this course are coming soon to Brainlag Learn. See courses