13. Program Construction Flashcards
What are the 4 stages of program construction?
- Lexical analysis
- Syntax analysis
- Semantic analysis
- Code generation and optimisation
What happens during lexical analysis?
- comments, unnecessary spaces and line breaks are removed
- keywords, constants and identifiers are replaced by tokens (usually hex tokens)
- these tokens allocate a machine code value to each identifier to identify them in the computer’s memory
What is an identifier table?
Identifies all of the variables/ constants in the program and their data types
What is a reserved word table?
Identifies all of the words native to the programming language being used e.g. input, output
What happens during syntax analysis?
- tokens are checked to see if they match the spelling and grammar expected by analysing each token to determine whether they are using the correct syntax
- if syntax errors are found, error messages are produced
What happens during semantic analysis?
- variables are checked to ensure they have been properly declared and used, and that they are the correct data type
- operations are checked to ensure they are legal for the type of variable they are being used on
What happens during code generation and optimisation?
- constructs in high level languages are replaced by machine code
- the code is optimised so that it is more efficient
What are the aims of code optimisation?
- achieve the required output of the program
- increase the speed of the program
- decrease demand on resources
- not delay the overall compilation process
What is a translator?
A program that converts source code (high level languages) into machine/object code.
What is a compiler?
- takes the source code and translates it all in one go
- once converted it can be run at any time, but the entire source code file has to be successfully compiled first
- compilers can also optimise code
adv:
- programs run quickly as its already been completely translated
- supplied as an executable file, therefore source code cannot be easily modified
disadv:
- code is translated as a whole, so enough memory must be available to store all the code at once
- cannot spot errors
- must be recompiled every time source code is changed
- object code produced is specific to processor’s architecture
What is an interpreter?
- translates source code one instruction at a time
- the resulting machine code is executed immediately
- this process is called interpretation
adv:
- instructions are executed as soon as they are translated
- requires less memory as instructions do not need to be stored for later use
- errors can be spotted quickly
disadv:
- interpreters run slower
- program has to be translated every time it is ran
- interpreters do not produce an executable file, so when being distributed the source code must be provided, which could be modified without permission
- interpreters do not optimise code
What is an assembler?
A program that converts assembly language into machine code.