Skip to content

Compiler and Interpreter

Both are language translators that convert programs written in High-Level Language (HLL) (like C, Java, Python) into Machine Language (Binary), so that the computer can understand and execute them.


1. Compiler

  • Definition: A compiler translates the entire program (source code) into machine code at once.
  • After compilation, an object code (executable file) is generated.

Features of Compiler

  • Translates the full program before execution.
  • Errors are displayed after complete compilation.
  • Execution is faster (because translation is done once).
  • Example Languages: C, C++, Java (partly).

Advantages

  • Fast execution.
  • Object code can be saved and reused without recompilation.

Disadvantages

  • Error detection is difficult (errors are shown only after compilation).
  • Requires more memory.

2. Interpreter

  • Definition: An interpreter translates and executes the program line by line.
  • No separate object code is generated.

Features of Interpreter

  • Reads one statement, translates it, and executes immediately.
  • Errors are shown immediately (line by line).
  • Execution is slower (because translation happens every time).
  • Example Languages: Python, JavaScript, Ruby, BASIC.

Advantages

  • Easier for beginners (errors are detected instantly).
  • Uses less memory (no object code storage).

Disadvantages

  • Slow execution speed.
  • Program must be translated every time before running.

Comparison Table: Compiler vs Interpreter

FeatureCompilerInterpreter
Translation MethodEntire program at onceLine by line
SpeedFaster executionSlower execution
Error DetectionErrors shown after compilationErrors shown immediately
OutputCreates object code (executable)No object code (direct execution)
Examples (Languages)C, C++Python, JavaScript, BASIC

Summary for Exams

  • Compiler → Translates whole program at once → Faster execution but delayed error detection.
  • Interpreter → Translates line by line → Slower execution but immediate error detection.