Programming

What is a Compiler?

A compiler translates source code written by humans into machine code or another target language a computer can execute.

A compiler is a program that translates source code written in a high-level language (like C, Rust, or Go) into a lower-level form — usually machine code — that a computer can run directly. It's the bridge between the code you write and the instructions your CPU understands.

How It Works:

  1. Lexical analysis: Break code into tokens
  2. Parsing: Build a syntax tree from those tokens
  3. Semantic analysis: Check types and rules
  4. Optimization: Improve performance without changing behavior
  5. Code generation: Emit machine code or bytecode

Compiler vs. Interpreter:

  • Compiler: Translates the whole program ahead of time, then runs the result (fast execution)
  • Interpreter: Executes code line by line at runtime (more flexible, slower)

Why Compilers Matter:

  • Performance: Optimized machine code runs fast
  • Error catching: Many bugs are caught before running
  • Portability: Compile the same source for different platforms

FAQ

What's the difference between compiled and interpreted languages?

Compiled languages are translated to machine code before running (C, Rust). Interpreted languages are executed on the fly (Python). Many modern languages blur the line with JIT compilation.

What is JIT compilation?

Just-In-Time compilation converts code to machine code during execution, combining the flexibility of interpretation with the speed of compilation. JavaScript engines and the JVM use it.

Promote your content

Reach over 400,000 developers and grow your brand.

Join our developer community

Hang out with over 4,500 developers and share your knowledge.