Program Translators: Compilers, Interpreters, and Execution
Classified in Computers
Written on in
English with a size of 3.39 KB
Program Translators: Compilers and Interpreters
Programs written in a programming language need to be translated into machine code to be executed by the CPU. This task is carried out by translators.
Translators can be categorized into two main types based on the translation process:
- Interpreters: Take the original program (source code), translate each instruction, and execute it immediately.
- Compilers: Take the source code, translate it completely into object code, and then the translated program is executed.
The Compilation Process: Object Code and Linking
After compiling a program, the result is known as object code. Object code is a new program written in a language very similar to machine code, but it is still not executable by the CPU.
Following the compilation process, it is necessary to obtain the final machine code from the object code through a process called linking.
Advantages and Disadvantages of Translation Methods
We compare the characteristics of compilers and interpreters:
Compilers
- Single Translation: The translation is performed only once. After translation, the program can run repeatedly without needing to be re-translated.
- Optimization: It is possible to optimize (enhance) the resulting machine code automatically. This is because the compiler has a global vision of the entire program before execution, allowing it to detect possible redundancies or improvements.
- Source Code Independence: The source code is not needed during execution.
- Faster Execution: Program execution is significantly faster.
- Low Portability: Compilers offer little portability. After obtaining machine code through compilation and linking, the code is prepared for a particular CPU type and therefore may not be executed on other architectures.
- Error Handling: If there are syntax errors, they must be corrected in their entirety before moving on to the execution stage.
Interpreters
- Repeated Translation: The source code must be translated every time the program is run.
- Optimization Limitations: It is not possible to optimize the resulting machine code because the interpreter does not have a global vision of the program (it translates instruction by instruction).
- Source Code Dependency: The source code is required every time an execution occurs. If the goal is to protect proprietary algorithms so that nobody knows how they work, interpreters are not suitable.
- Slower Execution: Execution is slower because it involves simultaneous translation and execution.
- High Portability: Interpreters offer greater portability. If a translator-interpreter is available for different types of architecture, any program written can be executed on any of these architectures without special modifications.
- Error Handling: Syntax errors are detected when the program execution reaches the error location. When an error is detected, execution stops temporarily, allowing the user to correct the error and then continue execution from where it left off.