Compiler
A program that translates source code in one language into another — usually a high-level language into machine code or an intermediate form.
- Primary domain
- Software Engineering & Notation
- Sub-category
- Compilers & Domain-Specific Languages
In simple terms
A compiler is a program that reads code in one language (say, C or Rust) and produces an equivalent program in another (usually machine code the CPU can run). The translation happens once; the resulting binary runs many times.
More detail
A typical compiler is a pipeline:
- Lexer — splits the source into tokens (
int,+,42). - Parser — builds an abstract syntax tree from the tokens.
- Semantic analysis — name resolution, type checking.
- Intermediate representation (IR) — a simpler, language-neutral form. LLVM IR is famous.
- Optimisation — constant folding, inlining, loop transformations, vectorisation.
- Code generation — produce machine code for the target ISA.
- Linking — combine compiled units and resolve external references.
Variations:
- Ahead-of-time (AOT) — produces a binary you ship (
gcc,rustc,clang). - Just-in-time (JIT) — compiles at run-time inside the runtime (V8, HotSpot JVM, .NET CLR).
- Source-to-source / transpiler — produces another high-level language (TypeScript → JavaScript, Babel for newer JS → older JS).
- Cross-compiler — runs on host A, produces code for host B (common in embedded).
Compilers also produce debug info so debuggers can map a crash address back to your source line.
Why it matters
Compilers are how human-readable ideas become machine instructions. Good compilers make slow code fast; great ones make safe code possible by catching whole classes of bugs at compile time.
Real-world examples
-
GCC, Clang/LLVM, MSVC compile C and C++.
-
rustc compiles Rust; swiftc compiles Swift; go compiles Go.
-
The TypeScript compiler (
tsc) emits JavaScript. -
WebAssembly is a compilation target many languages now share.
-
The Zig compiler is now used by some projects as a C cross-compiler because it bundles libc and runs on every platform, replacing the traditional gcc/clang dance.
Common misconceptions
- “Compilers always produce machine code.” Many compilers target bytecode (JVM, .NET) or another high-level language (TypeScript → JS).
- “Compiled means fast, interpreted means slow.” Modern JITs can match AOT compilers; modern interpreters with good runtimes outrun many compilers.
Learn next
The dual to compilation is execution by an interpreter. For what compilers actually check, see type system.
Read this in a learning path
All paths →This topic is part of a learning path. Start in context to keep prev/next and progress tracking.
Relationships
- Requires
- Related
- Next
- Leads to
- Required by
Neighborhood
A visual companion to the relationships above. Click any node to visit that topic.