Nodea — logo

Compilation

Compilation is the process of translating source code — written by a programmer in a human-readable programming language — into a form the computer can understand and execute: machine code or an intermediate code. The program that performs this is called a compiler. It is one of the fundamental stages of software development in compiled languages such as C, C++, Rust and Go.

What the compilation process involves

Compilation isn't a single step but a sequence of phases that the source code passes through:

  • lexical analysis — breaking the code into the smallest meaningful units (tokens);
  • syntax analysis — checking that the tokens follow the language's grammar and building a syntax tree;
  • semantic analysis — verifying logical correctness, e.g. type compatibility;
  • optimization — transforming the code so it runs faster and uses fewer resources;
  • code generation — producing the final machine or intermediate code.

If the compiler encounters an error at any stage (for example, a syntax error), it stops and reports it to the programmer before the program is even produced. This greatly aids debugging.

Practical application

Compilation is a daily part of building desktop, system, game and server applications written in compiled languages. A compiled executable is optimized and runs without needing a compiler present — which is why programs are delivered to users in binary rather than source form.

The concept also has a broader meaning in web development. The related transpiler translates code from one high-level language into another (e.g. TypeScript into JavaScript), and WebAssembly lets code from languages such as C++ or Rust be compiled into a form that runs in the browser at near-native speed. In deployment pipelines, the compilation (build) stage is one of the first steps of a CI/CD pipeline.

Powiązane pojęcia

Najczęstsze pytania

How is compilation different from interpretation?

A compiler translates the entire source code into an executable form ahead of time, before the program runs. An interpreter executes the code line by line at run time, with no whole-program translation step. Compilation usually yields faster programs; interpretation offers more flexibility and easier testing.