Chapter 10 - Programming Language Translators (1.2) Flashcards
What is a Translator?
A program that converts high level source code into low level object code so that it can be executed by a computer, input is source code and output is object code
What are the 3 types of Translator?
- Compiler
- Interpreter
- Assembler
What is a Compiler?
Program that translates high level code into machine code all at once
What are some advantages of a Compiler? (3)
- Can be run without a translator
- Object code is more secure
- Don’t need to compile it when you want to run object code
What are some disadvantages of a Compiler? (3)
- Longer than using an Assembler or Interpreter
- If changes need to be made then the whole program needs to be compiled again
- Can only be executed on certain devices (specific to a certain processor and OS)
When is a Compiler used? (2)
- When a program needs to be run regularly with occasional change
- When the object code produced is going to be sold to users
What is an Interpreter?
Program that translates high level code into machine code line-by-line
What are some advantages of an Interpreter? (2)
- Stops whenever it detects an error, making it useful for debugging
- More portable as code can be executed on a range of platforms
What are some disadvantages of an Interpreter? (2)
- Requires an interpreter to run on different devices
- Code must be translated with an interpreter every time it’s executed
When is an Interpreter used?
When you need to test sections of code to check for any errors
What is Assembly code?
Low level language where each instruction translates to one machine code instruction, it’s platform specific
What is an Assembler?
Translates assembly code to intermediate code (bytecode) so that it can be executed as machine code
What are the 4 stages of compilation?
- Lexical Analysis
- Syntax Analysis
- Code Generation
- Optimisation
What is Lexical Analysis?
Removes unnecessary spaces and comments and performs simple error checking, keywords, variables, and constants are replaced with tokens, information about token associated with each
keyword or identifier is stored in a symbol table
What is Syntax Analysis?
Tokens analysed against the grammar and rules of the programming language, any that break the rules are flagged up as syntax errors and added to a list of errors, abstract syntax tree is then created (representation of source code)