Program Constructions

Cards (26)

  • Program Translator
    Compilers, Interpreters, Assemblers
  • Compilation process
    1. Lexical analysis
    2. Syntax analysis
    3. Semantic analysis
    4. Code generation
    5. Code optimisation
  • Source code
    Written by programmers in a high-level programming language
  • Translators
    Convert source code into object code (machine-readable form)
  • CPUs can only process 1's and 0's (machine code)
  • Machine Code
    Very low level language made up of coded instructions and data
  • Assembly Language
    Low level language with a small set of commands representing machine code, uses mnemonics
  • High Level Languages

    Easier for programmers to use than assembly language
  • Assembler
    Converts low level assembly programming language into machine language
  • Interpreter
    Converts high-level language program into machine code and executes it line by line
  • Compiler
    Translates a high level language program (source code) into machine code (object code) for execution at a later time
  • Benefits and drawbacks of compilers and interpreters
    • Interpreters are easier to use as errors are reported and corrected as execution continues
    • Interpreters are slower than compilers as they translate the same statements repeatedly
    • Compilers can produce more efficient object code than interpreters
    • Compilers require analysis and code generation only once
  • Keywords
    • Reserved words in the programming language with special meanings (e.g. if, else, while, for)
  • Identifiers
    • Symbols referring to names of variables, functions, classes etc.
  • Constants
    • Specific values in the source code representing numbers, characters, strings, or Boolean values
  • Operators
    • Symbols used to perform operations on data (e.g. arithmetic, comparison, logical)
  • Token
    Numeric representation of keywords and identifiers in lexical analysis
  • Parsing
    Analysing the structure of the source code based on the grammar of the programming language
  • Compilation process
    1. Lexical analysis
    2. Symbol table construction
    3. Syntax analysis
    4. Semantic analysis
    5. Code generation
    6. Code optimisation
  • Programming errors
    • Logical
    • Syntactical/Syntax
    • Runtime/execution
    • Linking
    • Rounding
    • Truncation
  • Logical errors
    • Cause incorrect output without crashing the program, harder to detect than syntax errors
  • Syntax errors
    • Occur when a command does not follow the expected syntax of the programming language
  • Runtime/execution errors

    • Occur when the program is running and are difficult to foresee before compilation
  • Linking errors
    • Occur when a programmer calls a function but the correct library has not been linked/imported
  • Rounding
    Approximating to the nearest whole number/tenth/hundredth etc.
  • Truncation
    Approximating to the nearest whole number/tenth/hundredth etc. by removing decimal places