20 min read
Translators: Assemblers, Compilers and Interpreters
Why programs must be translated into machine code, and how assemblers, compilers and interpreters differ.
Why Translation Is Needed
The CPU only understands machine code. Anything written in assembly or a high-level language (the source code) must be translated into machine code (the object code) before it can run. A translator is a program that does this.
Three Kinds of Translator
| Translators | ||
|---|---|---|
Compiling vs interpreting
Compiler vs interpreter
| Compiler | Interpreter |
|---|---|
| Translates the whole program before it runs | Translates and runs one statement at a time |
| Reports all errors after compiling; nothing runs until they are fixed | Stops at the first error it reaches — useful while learning |
| Produces an executable file; the source code is not needed to run it | No separate executable; the interpreter and source are needed every time |
| Compiled program runs fast | Usually runs more slowly |
| Examples: C, C++, Go | Examples: Python, JavaScript (in the browser), PHP |
Practice
Which translator translates and runs a program one statement at a time?
More lessons in Introduction to Programming · Next: The Programming Process · Previous: The Evolution of Programming Languages
