A-level Computing/WJEC (Eduqas)/Component 1/Program construction
Translators
editTranslation Errors
editThe Compilation Process
edit1. Pre-processor
edit- The pre-processor takes the source code and performs tasks such as merging the contents of one or more files and replacing string patterns with another
- The pre-processor scans the code for pre-processor directives
2. Lexical Analysis
edit- Comments and unneeded spaces are removed
- Converts the source code into a token stream - Numeric representation of the code and stores in a table
- Keywords, constants and identifiers are replaced by 'tokens' (generally hex numbers)
- 2 tables are created
- Reserved word table
- Identifier table
Examples of lexical analysis tables:
- Reserved Word
- User Identifier
3. Syntax Analysis
edit- Tokens are checked to see if they match the spelling and grammar expected. This is done by parsing each token to determine if it uses the correct syntax for the programming language
- If syntax errors are found, error messages are produced
4. Semantic Analysis
edit- Variables are checked to ensure that they have been properly declared and used
- Variables are checked to ensure they are of the correct data type
- Operations are checked to ensure that they are legal for the type of variable being used
5. Code generation
edit- Where code specific to the target machine is generated. Several lines of machine code tend to be generated for each high level instruction
6. Code optimisation
edit- High-level general programming constructs are replaced by codes
- The replacement codes are very efficient low-level programming codes
➡️ EXAM QUESTION - what are the objectives 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