A compiler translates an entire source program before execution, whereas an interpreter translates and executes one instruction at a time. Both are translators, but differ in translation timing, error handling, and whether reusable executable code is produced.
In A1.4 Translation (HL only), source code is a program written in a high-level language. A translator converts it into a form the processor can execute, ultimately machine code.
A compiler analyzes the whole program before execution. If translation succeeds, it usually produces object code or an executable that can be stored and run repeatedly without recompiling the source. Errors are reported during compilation, often together after analysis.
An interpreter translates one instruction, executes it, and then continues. It usually stops at the first error, preventing later instructions from running. Because no separate executable is normally produced, the source program must usually be interpreted each time.
| Feature | Compiler | Interpreter |
|---|---|---|
| Translation | Complete program before execution | One instruction translated and executed at a time |
| Errors | Often reports multiple errors during compilation | Usually stops at first error |
| Execution | Compiled program generally runs faster | Generally slower because translation occurs while running |
| Output | Usually object code or executable | Usually no separate executable |
| Portability | Executable may depend on processor or operating system | Source runs wherever suitable interpreter exists |
| Development | Requires compile-test cycle | Immediate execution supports rapid testing |
A common misconception is that compiled languages are always compiled and interpreted languages are always interpreted. Some systems combine both methods, for example by compiling source into intermediate bytecode and then interpreting or just-in-time compiling it.
For an IB compare question, identify the translation unit and timing first, then explain consequences for errors, execution speed, portability, and repeated execution. Avoid saying only that a compiler is “faster”; state that the resulting compiled program generally executes faster.