A-level Computing/WJEC (Eduqas)/Component 1/Program construction

1. Pre-processor

 * 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

 * 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


 * 1) Reserved word table
 * 2) Identifier table

Examples of lexical analysis tables:


 * Reserved Word
 * User Identifier

3. Syntax Analysis

 * 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

 * 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

 * 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
"➡️ EXAM QUESTION - what are the objectives of code optimisation?"
 * High-level general programming constructs are replaced by codes
 * The replacement codes are very efficient low-level programming codes
 * 1) Achieve the required output of the program
 * 2) Increase the speed of the program
 * 3) Decrease demand on resources
 * 4) Not delay the overall compilation process