Compilers are software programs that convert code in a source language into another target language. The most common type are compilers from high-level languages to assembly code. Compilers also include high-level to high-level compilers, regex, database queries, and HTML templates.

Compilers translate from one language to another.

Main functions of compilers:

  • To read the input program in its entirety.
  • Checks for and reports errors.
  • If error-free, we translate to the target language (like machine code).
  • And program execution is after compilation.

They’re kinda magic lol http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf

Sub-pages

Resources

Structure

Modern compilers contain a number of distinct phases. These steps start by being language-dependent in the compiler front-end, before taking machine-dependent steps (like optimisations). The diagram below shows this structure:2 The role of the front-end is to read the input high-level language, check for errors, and generate an intermediate representation. The optimiser converts IR to IR, and improves it over multiple passes.

More specifically, compiler phases involve these main components:

  • Source code is passed into a lexer and parser. This generates an abstract syntax tree.
  • The AST is passed into an optimiser. This outputs an internal/intermediate representation.
  • This is then passed into a code generator (often called the back-end), for the target language.

See also

Footnotes

  1. Described by Prof Abdelrahman as pretty complex, mainly for compiler optimisations.

  2. From Computer Organization and Design: RISC-V Edition by David Patterson and John Hennessy.