- Foundation
- About 13 min
- 5 practice questions
Language translators: assembler, compiler and interpreter
Explain why translators are needed and compare compilers and interpreters.
If something looks wrong, please tell us.
People write programs in languages they can read, but a computer runs only machine code. Translators close that gap, and the difference between a compiler and an interpreter is a classic question.
Levels of language
- Machine language: binary 0s and 1s, understood directly by the CPU.
- Assembly language: short codes like ADD and MOV, closer to the machine.
- High-level language: close to English, such as C, Java or Python, and easy for humans to write.
The three translators
| Translator | Translates | How |
|---|---|---|
| Assembler | Assembly language to machine code | Converts the program to machine code |
| Compiler | High-level language to machine code | Translates the whole program first, then it runs |
| Interpreter | High-level language | Translates and runs one line at a time |
Compiler versus interpreter
- A compiler reports all errors after scanning the whole program; an interpreter stops at the first error it meets.
- A compiled program runs faster once built because it is already translated.
- An interpreter is handy for learning and testing because you see results line by line.
Worked examples
Example 1. A program has errors on line 3 and line 9. An interpreter shows the line 3 error and stops. A compiler lists both errors after reading the whole program.
Example 2. Which translator would convert a program written in assembly language? An assembler.
Assembler: assembly to machine. Compiler: whole program at once. Interpreter: line by line.
Key takeaways
- Three levels: machine, assembly, high-level.
- Assembler, compiler and interpreter are all translators.
- Compiler = whole program; interpreter = one line at a time.
Check your understanding
-
1. Which translator converts a program written in assembly language into machine code?
- Compiler
- Interpreter
- Assembler
- Web browser
Show answer
Answer: C. An assembler translates assembly language into machine code. Compilers and interpreters work on high-level languages.
-
2. A program has errors on line 3 and line 9. What does an interpreter do?
- It lists both errors after reading the whole program
- It shows only the error on line 9
- It runs the whole program without reporting any error
- It shows the error on line 3 and stops
Show answer
Answer: D. An interpreter translates and runs one line at a time, so it stops at the first error it meets, on line 3. Listing both errors after reading the whole program is what a compiler does.
-
3. Which translator translates the whole high-level program first, and then the program runs?
- Interpreter
- Compiler
- Device driver
- Text editor
Show answer
Answer: B. A compiler translates the whole program before it runs. An interpreter works line by line; a driver and an editor are not translators.
-
4. Short codes such as ADD and MOV belong to
- Machine language
- Assembly language
- High-level language
- Plain English
Show answer
Answer: B. Assembly language uses short codes like ADD and MOV and is close to the machine. Machine language is pure 0s and 1s.
-
5. Why does a compiled program usually run faster than the same program run through an interpreter?
- It has already been translated into machine code before it runs
- It is translated again line by line every time it runs
- It does not need the CPU
- It is stored as firmware
Show answer
Answer: A. Once a compiler has built the program, it is already translated, so it runs faster. An interpreter has to translate as it runs.
Sign in to keep track of the lessons you finish.