Interpreter
Интерпретатор
An interpreter is a program that carries out another program’s instructions. It can work from source code or from a form prepared for execution, such as bytecode.
What an interpreter does
A compiler translates a program; an interpreter runs it. For example, when an interpreter encounters a loop, it tests the condition, runs the body when appropriate, and repeats until the loop ends. A compiler might turn that same loop into instructions and jumps without ever running it. Many runtimes do both: they compile source code into bytecode, then use an interpreter to execute the bytecode.
How interpretation works
A simple interpreter can walk an abstract syntax tree (AST). For an expression like 2 + 3 * 4, the tree puts multiplication inside addition, so the interpreter evaluates 3 * 4 before adding 2. A bytecode interpreter instead works with a sequence of instructions. It fetches an instruction, dispatches to the code that implements it, and moves on to the next instruction or jumps elsewhere. The processor runs the interpreter’s own machine code; it does not have to understand the bytecode itself.
Example: why a Python script might print nothing
Consider this file:
print("Starting")
if True
print("Ready")
Run the file with CPython and you get a SyntaxError, not Starting. The missing colon prevents CPython from parsing the file, so it never reaches bytecode execution. If you enter print("Starting") as a separate command in the interactive prompt, it runs immediately. That difference is about what gets submitted as a unit, not whether CPython has a compilation step.
Where interpreters are used
Interpreters are common in scripting runtimes, command shells, and applications that embed a language so users can automate tasks or extend behavior. Runtimes can also mix interpretation with just-in-time (JIT) compilation. For example, a JavaScript engine can start by interpreting bytecode and later compile frequently executed code to native machine code. This trades the cost of compiling at runtime for the chance to avoid repeated work in the interpreter.
What interviewers look for
Be specific about the implementation rather than labeling an entire language as compiled or interpreted. If asked whether interpretation makes Python slow, distinguish time spent stepping through bytecode from work done elsewhere. A loop written in Python may incur interpreter overhead on each iteration, while a call into a native library may do most of its work in compiled code. Measure the workload before drawing a performance conclusion.