P2 T2 L4 Programming Language Translators Flashcards
1
Q
Define translators (1 point)
A
- Software that converts a program from one language to another
2
Q
What are the types of translators? (3 types)
A
- Compiler
- Assembler
- Interpreter
3
Q
What does a compiler do? (1 point)
A
- translates high level language into machine code by translating all of the code at once
4
Q
What does an assembler do? (1 point)
A
- translates a program written in assembly language to machine code
5
Q
What does an interpreter do? (2 points)
A
- Translates a program written in a high level language to another language.
- Converts the code line by line.
You may use this if you are trying to run a program on a different computer than the one you wrote it on as it might have a different processor.
6
Q
Explain the compiler (4 points)
A
- Translates high level language into machine code by translating all of the code at once.
- The compilation is done before execution.
- It turns the code into object code and executes it.
- Display all errors after compilation, all at the same time.
7
Q
Reasons to use a compiler (4 reasons)
A
- So that source code cannot be accessed by users;
- Users do not need to have an interpreter / compiler / translator. Users do not need to install an IDE (e.g. NetBeans)
- Users do not need knowledge of the programming environment
- So that the program will execute more quickly (when complete)
8
Q
Explain an interpreter (3 points)
A
- Converts the code line by line so the program can run with errors in it
- May either convert the code into machine code and execute it OR call instructions to carry out the high level language
statements in the source code. - Displays error of each line one by one.
9
Q
Reasons to use an interpreter (3 reasons)
A
- Can’t know what type of processor will be in user’s computer. Internet users have range of computers / devices with different processors.
- A compiled program will only execute on a processor of specific type / with same instruction set.
- A program run using an interpreter can execute on a computer with any type of processor.
10
Q
Explain Bytecode (3 points)
A
- Some programming languages use/support Bytecode.
- Bytecode is set of instructions (object code) used for programming that can be executed on any computer using a virtual machine. Eg JVM
- The virtual machine converts each generalised machine instruction into a specific machine instruction or instructions that this computer’s processor will understand.
11
Q
How do we use bytecode? (2 points)
A
- Once the bytecode for a particular subroutine or method has been translated into machine code, the machine code is retained for the next time that code is required, so the translation does not have to be done again.
- Using a language that comes with a virtual machine for each platform, your source language statements need to be compiled only once and will then run on any platform – usually speeds up Java execution
12
Q
What is source code? (1 point)
A
- Code which has not yet been compiled into an executable file
13
Q
What is object code? (2 points)
A
- Compiled code which can be run as an executable file on any computer
- Difficult to reverse engineer