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)
What is Code Generation?
Abstract syntax tree used to produce machine code
What is Optimisation?
Searches through the code to make it more efficient so that it’s faster to execute
What is a Static Linker?
Piece of software that is responsible for linking external modules and libraries included within the code, in a static linker, modules and libraries are added directly to the main file which increases its size and any external updates to modules and libraries don’t effect the program
What is a Dynamic Linker?
Piece of software that is responsible for linking external modules and libraries included within the code, in a dynamic linker, addresses of modules and libraries are added to the file where they’re referenced so that when the program is run, the loader retrieves the program at the specified address so that it’s executed, files remain small and external updates can go to the main file
What is a Loader?
Retrieves the library/sub-routine from the given memory location
What are Libraries used for?
They provide a specialised range of functions which would usually take alot of time and effort to develop
What is a Library?
Pre-compiled programs which can be used within other programs using static or dynamic linking, they’re ready to use, error free and can be reused within multiple programs