We are concerned with high-level languages which can be implemented by:

  • Compiling programs into machine language
  • Interpreting programs
  • A hybrid method combining both

Compiler

The compiler translates the source language into machine language that can be executed directly on the computer. The main phases include:

  • Lexical Analysis
  • Syntax Analysis (Parsing)
  • Type and Semantics Analysis
  • Machine Code Generation
Link to original

The execution of machine code occurs in a process called fetch-execute cycle, each machine instruction to be executed is moved from memory to the processor. The cycle performs the following:

  1. Initialise program counter
  2. Repeat forever:
    1. Fetch instruction pointed to by PC
    2. Increment PC
    3. Decode and execute instruction

Interpreter

An interpreter simulates a machine whose fetch-execute cycle deals with high-level program instructions. In this case there is no translation, the interpreter provides a virtual machine for the language. This is much easier to implement and debug but it has much slower execution.

Link to original

Hybrid Compiler and Interpreter

A hybrid implementation can compile to an intermediate language instead of machine language which can then be executed quickly. This gives us portability to any machine that has an interpreter for the IL.

Link to original