Compiler
A compiler is a program that translates source code written in one language, usually a high-level programming language, into another form, most often machine code for a particular processor or an intermediate representation, before the program is run. The translation is done once, ahead of execution, and its result can then be run repeatedly without the compiler being present. Compilers are what allow people to write in terms of variables, loops and functions while still getting programs that run at close to the speed of hand-tuned machine instructions.
The word and the idea trace back to Grace Hopper, whose A-0 system of 1952 for the UNIVAC I is generally cited as the first compiler. A-0 was closer to what is now called a linker or loader, since it pulled together pre-written subroutines identified by call numbers, but it established the principle that the machine itself could assemble programs from higher-level descriptions. The decisive demonstration of full translation was Fortran, delivered in 1957 by a team at IBM led by John Backus. Many doubted that automatically generated code could compete with hand-written assembly, so the Fortran compiler was built with heavy optimization, and its success made high-level languages practical. Hopper later championed English-like business programming, which led toward COBOL.
A classic compiler works as a pipeline of stages, each handling a different kind of problem. Lexical analysis, or lexing, breaks the character stream into tokens such as keywords, names, numbers and operators. Parsing arranges the tokens into a tree according to the language's grammar, an abstract syntax tree, and reports syntax errors. Semantic analysis then checks meaning, such as whether a variable was declared and whether types match. The compiler lowers the tree into an intermediate representation, a simplified form independent of both source language and target machine, on which optimization runs: removing dead code, computing constants in advance, inlining small functions, and moving work out of loops. Code generation finally selects instructions, allocates the processor's limited registers and emits object code, which a linker combines with libraries into an executable.
Modern compilers are built around shared infrastructure so one optimizer can serve many languages and many processors. GCC, started by Richard Stallman in 1987, supports many languages and targets. LLVM, begun by Chris Lattner and Vikram Adve at the University of Illinois around 2000, defines a well-specified intermediate representation and libraries for optimizing it and generating code; Clang for C and C++, Rust and Swift all use it as a back end. With N languages and M targets, a shared representation needs roughly N front ends and M back ends instead of N × M compilers. The same approach now drives machine learning: frameworks compile computation graphs into fused GPU kernels through tools such as XLA, TVM and MLIR, and a compiler's ability to schedule memory and parallel work is a large part of the performance of AI hardware.
A compiler is often contrasted with an interpreter, but the boundary is blurrier than the textbook picture suggests. An interpreter executes a program directly, translating and running it as it goes, which gives instant feedback and easy portability at a cost in speed. Compilation moves the translation cost to build time and enables whole-program optimization. In practice, Java and C# compile to bytecode for a virtual machine, and just-in-time compilers translate hot code to machine code while the program runs; Python's standard implementation compiles source to bytecode before interpreting it. A further common misconception is that a compiler makes programs correct: it checks syntax and, in typed languages, many type errors, but a program that compiles can still compute the wrong answer, and compiler optimizations are themselves software that can occasionally have bugs, which is why testing remains necessary.
Read a compiler as an automated translator and optimizer: from Hopper's A-0 and Backus's Fortran to LLVM, it converts readable source into efficient machine instructions through a pipeline of lexing, parsing, analysis, optimization and code generation, doing at build time the work an interpreter would otherwise repeat while the program runs.