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 language translator — compilers, interpreters and assemblers — and the stages of compilation. The OCR H446 specification requires you to understand how each translator works, compare them, and describe the stages of the compilation process.
Computers can only execute machine code (binary). Programmers write code in high-level languages or assembly language, which must be translated into machine code before the CPU can run it.
| Source Language | Translator | Target |
|---|---|---|
| Assembly language | Assembler | Machine code |
| High-level language | Compiler | Machine code (executable file) |
| High-level language | Interpreter | Machine code (executed line by line) |
An assembler translates assembly language into machine code.
| Feature | Detail |
|---|---|
| Input | Assembly language source file |
| Output | Machine code (object file) |
| Translation | One-to-one — each assembly mnemonic maps to exactly one machine code instruction |
| Passes | Most assemblers are two-pass: the first pass builds a symbol table (mapping labels to addresses); the second pass generates machine code using the symbol table |
| Pass | Action |
|---|---|
| Pass 1 | Scan the source code. Record all labels and their memory addresses in the symbol table. Check for syntax errors |
| Pass 2 | Translate each mnemonic into its machine code equivalent. Replace labels with addresses from the symbol table. Generate the final machine code |
A compiler translates the entire high-level source code into machine code before the program runs. The output is a standalone executable file.
| Feature | Detail |
|---|---|
| Input | High-level source code (e.g. a .c, .java, or .cpp file) |
| Output | Machine code executable (e.g. .exe) or bytecode |
| When translation happens | Before execution — the entire program is translated at once |
| Error reporting | Reports all errors after compilation. The program will not compile if there are syntax errors |
| Execution speed | Fast — the executable runs directly as machine code with no further translation |
| Distribution | The executable can be distributed without the source code |
| Portability of output | The executable is platform-specific. Must recompile for different architectures |
An interpreter translates and executes high-level source code one line (or statement) at a time, without producing a separate executable file.
| Feature | Detail |
|---|---|
| Input | High-level source code |
| Output | No separate file — code is executed directly |
| When translation happens | During execution — each line is translated and executed immediately |
| Error reporting | Stops at the first error encountered, reporting it immediately. Good for debugging |
| Execution speed | Slower — each line must be translated every time it is executed (e.g. in a loop) |
| Distribution | Source code must be distributed (or an interpreter must be bundled) |
| Portability | The same source code runs on any platform with a compatible interpreter |
| Feature | Compiler | Interpreter |
|---|---|---|
| Translation | Entire program at once | Line by line during execution |
| Output | Standalone executable file | No separate file |
| Execution speed | Fast (pre-compiled) | Slower (translated at runtime) |
| Error detection | All errors reported after compilation | Stops at the first error |
| Debugging | Harder — must recompile after changes | Easier — can test changes immediately |
| Source code distribution | Not needed — only executable distributed | Source code required |
| Memory usage | Needs enough memory to compile the whole program | Only needs to hold one line/statement at a time |
| Re-translation | Only when source code changes | Every time the program runs |
| Use a Compiler When... | Use an Interpreter When... |
|---|---|
| The program is complete and ready for distribution | During development and debugging |
| Execution speed is critical | Rapid prototyping and testing |
| You want to protect source code from users | The program must be portable across platforms |
| The program will be run many times | The program is a script run occasionally |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.