Tech

Compiler

A compiler is like a translator who takes a whole cookbook written in a foreign language and prints a brand-new English edition of it.

  • 3 min read
  • 1 figures
  • Verified 2026-10-13

Definition

A compiler is a program that turns code written in a human-friendly language into machine code a computer can usually run directly (some compilers translate into another intermediate language instead). It doesn't translate line by line on the fly. It reads the whole manuscript and produces a new file in one go. That's why the machine-code file can run on its own later, with no translator around.

The person who translates the whole cookbook

Say you get a cookbook written in a foreign language. To cook from it, you need to read the words, but you don't speak that language. So you hand the whole book to a translator and get back a brand-new English edition.

Computers are in the same boat. People write programs in a language that's easy to read, but the only language a computer understands is machine code, made of 0s and 1s. The manuscript a person writes is called source code, and the translator that turns it into a machine-code file is the compiler.

The translation is finished before the program ever runs. So you don't need to translate again every time you launch it, and the translated file runs right away. Most programs you download and run are files that were translated ahead of time like this.

The translator catches typos, too

A translator doesn't just move words from one language to another. If the manuscript has a missing word or a sentence that doesn't make sense, they stop and flag it. Forcing a meaningless sentence into the translation would give you a strange cookbook.

A compiler also reads the whole manuscript and looks for anything that breaks the rules. If you forgot to close a parenthesis, or put letters where a number belongs, it stops translating and tells you which line has the problem. A problem caught during translation like this is called a compile error.

Thanks to this, you can catch mistakes before you ever run the program. Once it has read the whole manuscript, the compiler also polishes the writing. For example, it might shrink a spot that repeats the same calculation many times down to a single time, so the translated program runs faster.

A bit more precisely: a translation has a specific reader

The English cookbook you got from the translator is only useful to people who read English. To give the same manuscript to someone in another country, you'd have to translate it again into their language.

Machine code works the same way. The computer's brain, the central processing unit (CPU), understands different machine code depending on its type (for example, a typical PC chip versus a smartphone chip). The file format for programs and the way a program asks the operating system for help also differ among Windows, Linux, and Mac, so even with the same brain, a file may not open as is. That's why an executable made on one machine may not open on another. In that case, you translate the same manuscript again to fit that computer's CPU and operating system.

There's also another approach: calling in an interpreter instead of a translator. It reads the recipe aloud to you one line at a time while you cook. In the programming world, this kind of tool is called an interpreter. You can start right away because nothing was translated in advance, but the interpreter has to stay by your side the whole time the program runs.

Common misconceptions

Myth

A compiler is a tool that runs your program.

Fact

The operating system and the CPU do the running. A compiler's job ends once it has prepared a file that can be run.

Myth

If compiling succeeds, the program has no mistakes.

Fact

What the translator catches are sentences that break the grammar rules. A mistake where the grammar is fine but the order of calculations is wrong only shows up when you run the program.

Where you meet it

  1. You can download a game or an office app and run it right away because its makers translated it into machine code ahead of time.

  2. When you save your code, hit the build button, and see a message like "missing parenthesis on line 12," that's a compile error.

In one sentence

A compiler is a translator that converts all the code a person wrote into a machine-code file ahead of time, and catches grammar mistakes along the way.

Created 2025-11-01 Updated 2026-10-13 Verified 2026-10-13