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

From Wikibooks, open books for an open world
Jump to navigation Jump to search

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
  1. Reserved word table
  2. 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?

  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