Section 1: Fundamental Concepts of Translation
Why must programs be translated into machine code before execution?
CPU hardware can only process instructions in machine code (binary) because its made up of logic gates. Therefore, any program written in a high-level or assembly language must be converted into machine code and loaded into main memory to run.
What is the definition of a Translator?
Systems software that converts a source program written in a language other than machine code into a format that the computer can execute.
What is a Source Program?
The original program written by the programmer in a high-level or assembly language before it has been translated.
What is an Object Program (Object Code)?
The machine code version of a program that is produced after the source code has been processed by a compiler or assembler.
How does the mapping of instructions differ between low-level and high-level languages?
Low-level language instructions generally have a one-to-one mapping with machine code, whereas one high-level language instruction usually translates into multiple machine code instructions.
What is the definition of machine independent?
The program code can be translated to run on any processor / platform
Section 2: Types of Translators
What is an Assembler?
A program that translates a source program written in a low-level assembly language into machine code.
What is a Compiler?
A program that translates a source program written in a high-level language into machine code or p-code (object code) as a single, complete unit.
What is an Interpreter?
A program that analyzes and executes a high-level language program line by line without producing a separate object code file.
What is bytecode?
It is partially complied code that is generated using a compiler. This bytecode can only be interperted on a virtual machine and is machine independent.
Describe how Java source code is translated.
Section 3: Performance and Resource Management
How does execution speed compare between compiled and interpreted programs?
Compiled programs run faster because the translation is performed once before execution; interpreted programs run slower as each line must be translated every time the program is executed.
How do compilers and interpreters differ in their use of memory during execution?
A compiled program only requires the object code to be in memory. An interpreted program requires both the source code and the interpreter software to be present in memory during execution.
Which translator is more efficient for programs that use loops?
A compiler, because it translates the loop code once. An interpreter must re-translate every instruction inside the loop for every iteration.
Section 4: Development and Security
Why is an interpreter often preferred during the initial development phase of a program?
It allows for faster testing and debugging because the programmer can see the results of changes immediately without waiting for a lengthy compilation of the entire project.
How do compilers and interpreters handle error reporting differently?
A compiler scans the entire program and provides a complete list of all syntax errors at the end. An interpreter stops execution the moment it encounters a single error.
Why is a compiler better for protecting Intellectual Property (IP)?
A compiler produces an object code file that is difficult for humans to read or reverse-engineer, allowing the developer to distribute the software without sharing the original, readable source code.
How does portability differ between compiled and interpreted code?
Compiled object code is often specific to a particular hardware architecture. Interpreted source code can run on any machine as long as a compatible interpreter is installed on that system.
Section 5: Errors and Debugging
What is a Syntax Error?
An error in the grammar or rules of the source program (e.g., a misspelled keyword or missing punctuation) that prevents translation.