Compiler
A program that translates source code into another form, ahead of running it, checking it along the way.
Compiler translates a program from one language into another — typically source code into machine code or bytecode — before the program runs, as a distinct step from execution. This "ahead of time" property is the definitional contrast with an Interpreter, which reads and executes source directly, one step at a time, without producing a separate translated artifact first.
A compiler's pipeline is usually lexing (characters into tokens), parsing (tokens into an abstract syntax tree), semantic analysis (type checking, scope resolution — the phase that catches most of what a reader thinks of as "compiler errors"), optimization (rewriting the tree or an intermediate representation into an equivalent but faster form), and code generation (emitting the target language). Each phase can reject the program before ever reaching the next one, which is why a compiled language tends to catch entire classes of bugs — a misspelled variable, a type mismatch, a missing case in a Pattern Matching match — before a single instruction runs, unlike an interpreted script that fails only when execution reaches the bad line.
The line between compiler and interpreter has blurred in practice: most production JavaScript and Java runtimes use a JIT (just-in-time) compiler, which starts by interpreting bytecode and compiles the hot paths to native code partway through execution, getting an interpreter's fast startup and a compiler's steady-state speed. TypeScript compiles to JavaScript rather than machine code — a "transpiler," informally — but does the same essential job: translate ahead of running, and reject what doesn't type-check along the way.
The trade-off a compiler imposes is a build step between writing code and seeing it run, which costs iteration speed compared to an interpreter's immediate feedback — the reason a scripting language is often preferred for exploratory work and a compiled one for anything shipped, even when both are available for the same problem.
See also4
Interpreter
A program that executes source code directly, statement by statement, without a separate translation step first.
Computation & Algorithms7 connections
Type Inference
A compiler deriving a value's type from how it's used, so a programmer doesn't have to write it down.
Computation & Algorithms6 connections
Pattern Matching
Testing a value against a shape and binding its parts to names in one step, instead of inspecting it field by field.
Computation & Algorithms6 connections
Garbage Collection
A runtime automatically reclaiming memory occupied by objects nothing can reach anymore.
Computation & Algorithms6 connections
Linked from5
- Garbage CollectionComputation & Algorithms
A runtime automatically reclaiming memory occupied by objects nothing can reach anymore.
- InterpreterComputation & Algorithms
A program that executes source code directly, statement by statement, without a separate translation step first.
- ReflectionComputation & Algorithms
A program inspecting or modifying its own structure — types, methods, fields — while it runs.
- Tail Call OptimizationComputation & Algorithms
Reusing a function's stack frame for a call in tail position so recursion runs in constant stack space.
- Type InferenceComputation & Algorithms
A compiler deriving a value's type from how it's used, so a programmer doesn't have to write it down.