A-level Computing/WJEC (Eduqas)/Component 1/Program construction
Appearance
Translators
[edit | edit source]Translation Errors
[edit | edit source]The Compilation Process
[edit | edit source]1. Pre-processor
[edit | edit source]- 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 | edit source]- 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 | edit source]- 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 | edit source]- 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 | edit source]- 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 | edit source]- 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