Translators Flashcards
What is a translator?
A translator changes a program written in one language into another language (usually machine code)
What is an assembler?
An assembler converts low level assembly language into machine code.
What is an Interpreter?
An interpreter converts high-level language one line at a time into machine code and executes it.
What is a Compiler?
A compiler converts high-level language into machine code for execution at a later time. The entire program is converted at once.
Differences between an interpreter and a compiler?
Execution Speed -
- An interpreter is slower than a compiler because the code must be reinterpreted each time the program is run
- Compliers can produce much more efficient code than interpreters making the compiled programs runs faster.
Complexity -
- Interpreters are smaller, simpler programs
- Compliers tend to be large complex programs
Error Reporting -
- In error reporting, the interpreter would encounter the errors and report it to the user immediately and stops the program from running.
- The compiler would analyse the entire program, taking note of where errors have occurred and record them in an error file.
What is Lexical Analysis?
- Spaces and comments are removed from the code
- Identifiers, keywords and operators are replaced by tokens. A token is similar to a variable with a name and a value.
- A symbol table is created. This table stores the addresses of all variables, labels and subroutines used in the program
What is Syntax Analysis?
- The tokens created in the first stage are checked to see if they follow the syntax rules of the programming language (parsing).
- During parsing, if a syntax error is found then an error message is displayed and compilation stops.
Semantic Analysis
- Variable checks ensure they are correctly declared and use a valid data type.
- Operation checks ensure they are correct for the data type.
Code Generation
The machine code is generated.
Code optimisation
The code is optimised so it is fast, efficient and uses a little of the computer’s resources as possible