Structure of Compiler

Translator

A translator converts source code from one language to another. Compilers, interpreters, and assemblers are all types of translators — the foundation of how any programming language runs.

What is a Translator?

A translator is a program that reads code written in one programming language (called the source language) and converts it into another language (called the target language).

Think of it like translating a book from French to English — the meaning stays the same, but the words change.

Source Code → [Translator] → Target Code / Execution
Source (Input)TranslatorTarget (Output)
C++ codeCompilerMachine code
Python codeInterpreterExecutes directly
Assembly codeAssemblerBinary machine code
TypeScriptTranspilerJavaScript

Types of Translators

There are three main types of translators:

1. Compiler

  • Translates the entire source program all at once before execution
  • Produces a separate executable file you can run later
  • Runs faster because translation only happens once
  • Example: GCC (for C/C++), javac (for Java)

2. Interpreter

  • Translates and executes the code line by line, on the fly
  • No separate output file is produced
  • Easier to debug interactively, but generally slower at runtime
  • Example: Python interpreter, JavaScript in a browser

3. Assembler

  • Translates assembly language (human-readable mnemonics) into machine code (binary 0s and 1s)
  • Works at a very low level, directly mapping to CPU instructions
  • Example: NASM (Netwide Assembler), GAS (GNU Assembler)

Compiler vs Interpreter

FeatureCompilerInterpreter
TranslationEntire program at onceOne line at a time
OutputExecutable fileNo file produced
Execution speedFastSlower
Error detectionAfter full compilationStops at first error hit
Example languagesC, C++, Go, RustPython, Ruby, JavaScript

Key Analogy: A compiler is like translating an entire book into English before you read it. An interpreter is like having a live translator whisper each sentence to you as you go.

Why Translators Matter

Every program you write eventually needs to be converted into something the CPU can understand — a sequence of binary instructions.

Without translators:

  • You would have to write raw machine code (0s and 1s) for every program
  • The same program would not work on a different CPU
  • Development would be slow, error-prone, and hardware-specific

Translators give us portability and productivity: write once in a high-level language, translate it to run on any machine.