Interpreter

An interpreter is a computer program that directly executes instructions written in a programming language, without requiring them to be compiled first.

Process: 1. Lexical Analysis (Tokens). 2. Parsing (AST). 3. Bytecode Generation. 4. Execution (Dispatch Loop). Comparison: Interpreter vs. Compiler.

        graph LR
  Center["Interpreter"]:::main
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧒 Explain Like I'm 5

Think of a chef reading a recipe. A '[Compiler](/en/terms/compiler)' is like translating the whole recipe into another language before you start cooking. An '[Interpreter](/en/terms/interpreter)' is like reading one step, doing it, then reading the next step, and doing it. It's slower, but if you realize you're missing an ingredient halfway through, it's easier to change the plan.

🤓 Expert Deep Dive

Technically, modern interpreters rarely execute raw source code. Instead, they use a two-step process: 1. Parse source code into an 'Abstract Syntax Tree' (AST). 2. Compile AST into 'Bytecode' (platform-independent instructions). The 'Virtual Machine' then interprets this bytecode. To improve performance, systems like the V8 engine (JavaScript) or the JVM (Java) use 'JIT (Just-In-Time) Compilation', where frequently used blocks of bytecode are compiled into native machine code during execution. This hybrid approach combines the portability of an interpreter with the speed of a compiler.

📚 Sources