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
- Widely available compilers
- Compiler front-end
- Compiler optimisation
- Compiler back-end
Resources
- Compilers: Principles, Techniques, and Tools, by Alfred Aho, Ravi Sethi, and Jeffrey Ullman (Dragon)
- Modern Compiler Implementation in {Java, ML, C}, by Andrew W. Appel
- Advanced Compiler Design and Implementation, by Steven Muchnick1
- Courses
- ECE467 — Compilers and Interpreters
- CS 6120 — Advanced Compilers, at Cornell University
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.