9618 · 5.2
Language Translators
Computers only understand binary instructions, known as machine code. Language translators act as interpreters, converting the high-level code we write into the low-level instructions the processor can execute.
Need to know
What you need to know
- **Compiler:** Scans the entire program first. It translates the whole source code into a standalone executable file (object code). This file can be run multiple times without re-compilation. Any errors are reported all at once after the entire scan.
- **Interpreter:** Processes the program line by line. It translates and executes the first line, then the second, and so on. It does not create a separate executable file. An error will halt execution at the line where the error occurred.
- **Execution Speed:** Compiled programs generally run much faster because the translation is already done. Interpreted programs are slower as translation happens during execution.
- **Distribution:** Compiled programs are easy to distribute as a single executable file. The end-user does not need the compiler. Interpreted programs require the user to have the interpreter installed.
- **Debugging:** Interpreters are often better for debugging as they pinpoint errors on the exact line they occur. Compilers report a list of errors which can sometimes be harder to trace back to the original cause.
- **Platform Dependence:** A compiled executable is specific to a CPU architecture and operating system. An interpreted program can run on any platform that has the correct interpreter available.
Explanation
From Human Code to Machine Speak
- A programmer writes source code in a high-level language like Python or Java.
- The source code is fed into a language translator program (e.g., a compiler or an interpreter).
- The translator converts the code. A compiler creates a complete, standalone executable file of machine code. An interpreter translates and runs the code line by line.
- The CPU executes the resulting machine code, carrying out the program's instructions.