# Compiler

URL: https://softwaredictionary.org/terms/compiler
Category: Programming Fundamentals
Last updated: 2026-09-30
In Turkish: Derleyici

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.

## 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 line

```bash
# 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
```

## Frequently asked questions

**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.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
