program structures

Cards (21)

  • Compilers
    Used when high level programming languages are converted into machine code ready to be executed by the CPU
  • Interpreters
    Before high level programming languages are run, code is converted one line at a time into machine code and executed by the CPU
  • Assemblers
    Convert a low level language (assembly language) into machine code
  • High-level languages are programming languages that look like normal English using the code use words that we can identify e.g. end, while, forever
  • Python is a high level language
  • High level programs have to be converted into machine code first (binary/hex)
  • Each instruction in a high level program is converted into many machine code instructions
  • Interpreted
    • Errors are reported and corrected as execution continues
    • Slower than a compiler as it translates the same statements within the loop over and over again
  • Compiled
    • Compiler would analyse the entire program, taking note of where errors have occurred, and places this in an error/diagnostic file
    • Compilation requires analysis and the generation of the code only once
    • Compilers can produce much more efficient object code than interpreters thus making the compiled programs to run faster
    • Displaying multiple errors the same time on the whole means compilers tend to be more difficult to use
  • Stages of Compilation

    • Lexical Analysis
    • Symbol table construction
    • Syntax Analysis
    • Semantic Analysis
    • Code Generation
    • Code Optimisation
  • Lexical Analysis

    Comments and spaces are removed – these are not needed for execution. Keywords, constants & identifiers are replaced by "tokens"
  • Symbol table construction

    A symbol table is created which holds the addresses of variables, labels and subroutines
  • Syntax Analysis

    Tokens (Keywords, constants & identifiers) are checked to see if they match spelling and grammar expected, using standard language definitions. This is done by parsing (checking) each token to determine if it uses the correct syntax for the programming language
  • Semantic Analysis

    Variables are checked to ensure that they have been properly declared and used. Variables are checked to ensure that they are of the right data type (e.g. real values not assigned to integers). Operations are checked to ensure that they are legal for the type of variable being used
  • Code Generation

    Machine code is generated
  • Code Optimisation

    May be employed to make the code more efficient/faster/less resource intense
  • Program Error Types

    • Syntax
    • Runtime/execution
    • Logical
    • Linking
    • Rounding
    • Truncation
  • Syntax Error

    Occurs when a command does not follow the expected rules or grammar of a programming language (detected during translation into executable code / attempted to run but fails)
  • Runtime/execution Error

    Occurs when the program is running and is difficult to foresee before it is compiled and run. The program is unexpectedly halted
  • Logical Error

    Causes the program to output an incorrect answer (doesn't necessarily crash the program). The logic of the program is incorrect
  • Linking Error

    Occurs when a program calls for a function and the correct library has not been linked to the program