Compiler
Program that translates source code written in one programming language, usually a high-level one, into another form such as machine code.
A compiler translates a program from the language a person wrote it in into a form a machine can run, typically processor-specific machine code or an intermediate bytecode. The whole program is translated ahead of time, producing output that can then be run repeatedly without the compiler. A C program, for instance, is compiled into an executable file for a particular processor and operating system. This differs from an interpreter, which executes source code more directly, although many language implementations combine both approaches.
Compilers typically work in stages. A lexer breaks the source text into tokens; a parser arranges them into a syntax tree; semantic analysis checks types and names; and later stages optimize the program and generate code. The A-0 system that Grace Hopper developed in 1952 is often described as one of the first compilers, and Hopper championed programming in English-like languages. The FORTRAN compiler delivered by John Backus's team at IBM in 1957 showed that compiled code could rival hand-written assembly in speed, helping high-level languages win acceptance.
Compilers are among the most consequential tools in computing, because every improvement to them benefits every program they build. Shared compiler infrastructures such as GCC, first released in 1987 as part of the GNU project, and LLVM, begun at the University of Illinois in 2000, underpin many languages. Type checking and warnings catch many errors before a program ever runs. Ken Thompson's Turing Award lecture, published in 1984 as "Reflections on Trusting Trust", showed that a compromised compiler could insert hidden backdoors into programs, an argument that motivates work on reproducible builds.
Key points
- A compiler translates an entire program ahead of time, producing output that runs without the compiler present.
- Typical stages include lexical analysis, parsing, semantic checks, optimization and code generation.
- The 1957 FORTRAN compiler helped prove that high-level languages could produce efficient programs.
- Ken Thompson showed that a compromised compiler can secretly insert backdoors into the programs it builds.
Related entries
Interpreter
Program that executes instructions written in a programming language directly, statement by statement, without first producing a standalone executable.
Just-in-Time Compilation
Technique that compiles code into native machine instructions while a program is running, combining interpreter flexibility with compiled speed.
Static Analysis
Examination of source code or binaries without executing them, using automated tools to find bugs, security flaws and quality issues.
Type System
Set of rules a programming language uses to assign types such as integer or string to values and to check that operations use them consistently.
Grace Hopper
American computer scientist and US Navy rear admiral who developed early compilers and helped create the COBOL programming language.
Ken Thompson
American computer scientist who created the Unix operating system and the B language and later co-designed the UTF-8 encoding and the Go language.
Reproducible Builds
Practice of making software builds deterministic so anyone can rebuild published binaries from source and get bit-for-bit identical results.
C
General-purpose programming language created by Dennis Ritchie at Bell Labs in the early 1970s, foundational for operating systems and embedded software.
Featured in guides
Referenced by
Other entries that discuss or point to Compiler.