1.8 Program Construction

Cards (16)

  • Assembler
    A program that converts a program written in assembly language / assembly code into object code / machine code
  • A programmer might choose to use an assembler program

    If the application requires maximum computer efficiency / performance
  • Interpreter
    Translates each line of the source program then executes it
  • Compiler
    Translates a whole (source code) program prior to execution
  • Lexical Analysis
    1. Input stream is broken into tokens
    2. Any comments and unneeded spaces are removed
    3. Symbol table is produced (could also be in Syntax Analysis)
    4. Error messages are generated if appropriate
  • Syntax Analysis
    The process of determining whether the sequence of tokens obey the rules of the syntax of the language
  • Syntax rules would be expressed as either Syntax diagrams or Backus Naur Form
  • Syntax Analysis
    1. Symbol table is produced (could also be in Lexical Analysis)
    2. Tokens are checked for matching the syntax, using BNF-type rules
    3. If not the case, error message(s) are produced
  • Semantic Analysis
    1. Checks that all variables are declared (and used)
    2. Checks that e.g. real values are not being assigned to integers
    3. Checks that operation is legal for data type (no mixed mode arithmetic)
  • Code Generation
    1. Object code is generated
    2. Most high level language statements will be translated into a number of machine code instructions
  • Code Generation
    Linking loaders would make sure that previously compiled code sections are loaded into the program and the required links created
  • Code Generation

    1. Code optimisation techniques attempt to reduce the execution time of the object program by, for example, spotting redundant instructions and producing object code which achieves the same net effect as that specified by the source program but not by the same means
    2. In optimisation, high-level general programming constructs are replaced by codes
    3. The replacement codes are very efficient low-level programming codes
  • Code optimisation objectives
    • Achieve the required output of the program
    • Increase the speed of the program
    • Decrease demand on resources
    • Not delay the overall compilation process
  • Code Generation

    1. Machine code is generated
    2. Code optimisation may be employed
  • Translation errors
    Occur during the conversion process. These could include Syntax errors or undefined variables/function
  • Execution errors
    Also called run-time errors. They are errors that occur once the program is being executed and are not an issue with the translation. A common execution error is 'divide by zero'