Definition
Compilation is the process of translating program source code written in a human-readable language into a lower-level form — typically machine code, bytecode, or another intermediate representation — that a computer can execute directly or run on a virtual machine. A compiler reads the entire program ahead of time, analyzes it for correctness, and emits an artifact (an executable binary, a .class file, a WebAssembly module) that contains no trace of the original syntax.
The contrast is with interpretation, where a program reads source code line by line at runtime and performs the requested operations immediately, without producing a standalone artifact. Most modern systems sit somewhere between the two: just-in-time compilers, bytecode VMs, and tiered optimisers blur the line by translating and executing in overlapping phases.
Why it matters
How it works
A traditional compiler runs in phases. The lexer breaks source text into tokens; the parser builds a syntax tree; semantic analysis checks types and resolves names; an intermediate representation is generated and optimised; finally a code generator emits target-specific machine instructions, and a linker resolves cross-file references into a single executable. Each phase produces input for the next, which is why a single syntax error early in the file can cascade into dozens of downstream diagnostics.
Interpreters skip the artifact step. Some walk the syntax tree directly; others compile to bytecode in memory and run it on a stack machine. Hybrid systems — Java's HotSpot, V8 for JavaScript, PyPy for Python — start interpreting, profile which functions run often, then compile those hot paths to native code while leaving rarely-executed code as bytecode. The compiler-vs-interpreter dichotomy turns out to be less a binary choice than a position on a spectrum of when translation happens and how aggressively it optimises.