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 also3
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 & Algorithms10 connections
Garbage Collection
A runtime automatically reclaiming memory occupied by objects nothing can reach anymore.
Computation & Algorithms14 connections
Lexical Analysis
The first stage of reading a program, which groups a stream of characters into tokens such as names, numbers, operators and keywords, usually using regular expressions compiled into a finite automaton, so the parser can work with words rather than letters.
Computation & Algorithms9 connections
Linked from10
- Garbage CollectionComputation & Algorithms
A runtime automatically reclaiming memory occupied by objects nothing can reach anymore.
- Graphics APIGraphics & Rendering
The programming interfaces through which software drives the GPU, from the driver-heavy OpenGL era to explicit modern APIs like Vulkan, Direct3D 12, and Metal.
- InterpreterComputation & Algorithms
A program that executes source code directly, statement by statement, without a separate translation step first.
- Lexical AnalysisComputation & Algorithms
The first stage of reading a program, which groups a stream of characters into tokens such as names, numbers, operators and keywords, usually using regular expressions compiled into a finite automaton, so the parser can work with words rather than letters.
- ReflectionComputation & Algorithms
A program inspecting or modifying its own structure — types, methods, fields — while it runs.
- Shader Compilation StutterGraphics & Rendering
Frame hitches caused by compiling GPU programs the first time they are needed, and the caching schemes that try to move that work elsewhere.
- Static AnalysisTesting & Verification
Finding bugs by examining code without running it, from linters and type checkers to deep security analysis, always trading missed bugs against false alarms.
- 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.
- Type SystemTesting & Verification
The rules a language uses to classify values and reject operations that don't fit, checked before the program runs or as it runs, and the cheapest form of verification most programmers use every day.