Skip to main content

Compiler

In Turkish
Derleyici
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/compiler

In short

A compiler is a program that translates source code written in a programming language into a lower-level form, such as machine code, that a computer can run.

What is a compiler?

A compiler converts the human-readable code you write into instructions a computer can execute. For languages like C, C++, Go, and Rust, the compiler produces machine code for a specific processor, packaged as an executable file. Other compilers, such as those for Java and C#, produce an intermediate format called bytecode, which a virtual machine then runs.

Compilation happens in stages. The compiler first reads the source code and breaks it into tokens, then parses those tokens into a tree that represents the program's structure, checks it for errors such as type mismatches, optimizes it, and finally generates the output code. Because all of this happens before the program runs, many mistakes are caught at compile time, long before a user sees them.

A compiler is like a translator who converts an entire book into another language before it is published, so readers get a finished translation. An interpreter, by contrast, is like a live interpreter who translates a speech sentence by sentence as it is being given. Languages like Python and JavaScript are traditionally interpreted, although modern engines such as V8 use just-in-time (JIT) compilation to turn frequently run code into machine code while the program is running.

The line between compilers and interpreters is blurry in practice, since many languages use both. A related term is transpiler, a compiler that translates between languages at a similar level, such as the TypeScript compiler (tsc), which turns TypeScript into JavaScript. Compile-time errors are also different from runtime errors: the first stop the program from building, while the second happen while it runs.

At a glance

A compiler turns source code into machine code in stages: it splits the text into tokens, parses them into a syntax tree, checks and optimizes the tree, and generates instructions for the processor.Source codex = a + 1Tokensx · = · a · + · 1Syntax treeparseChecktypes · optimizeMachine codemov · add=x+a1x = a + 1 as a treetype error, line 3caught before it runs
Mistakes such as a wrong type are caught at the checking stage, before the program ever runs.

Key takeaways

  • A compiler translates source code into machine code, bytecode, or another language.
  • It works in stages: tokenizing, parsing, checking, optimizing, and generating code.
  • Compile-time errors are caught before the program ever runs.
  • An interpreter runs code directly instead of translating it all ahead of time.
  • A transpiler, like the TypeScript compiler, converts code between similar high-level languages.

Example

Compiling programs from the command linebash
# Compile a C program into a native executable, then run it
gcc hello.c -o hello
./hello

# Compile Java source into bytecode for the Java Virtual Machine
javac Hello.java
java Hello

# Transpile TypeScript into JavaScript, then run it with Node.js
npx tsc app.ts
node app.js

Readers ask

What is the difference between a compiler and an interpreter?

A compiler translates the whole program ahead of time into another form, usually machine code, that runs later. An interpreter reads and executes the source code directly while the program runs; many modern languages combine both approaches.

Is JavaScript compiled or interpreted?

Both. JavaScript is often described as interpreted, but modern engines like V8, used in Chrome and Node.js, start with an interpreter and then compile frequently used code into optimized machine code on the fly, which is called just-in-time compilation.

What is a transpiler?

A transpiler, or source-to-source compiler, translates code from one high-level language to another, such as TypeScript to JavaScript. Tools like Babel also use transpiling to convert modern JavaScript into older syntax for compatibility.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings