interpreter

term

programming

Kept in this browser · My desk

A program that carries out another program directly, statement by statement or instruction by instruction, instead of first translating the whole of it into machine code.

Short Code on the UNIVAC (1950) was interpreted. The most famous interpreter was an accident: John McCarthy wrote the Lisp function eval for a paper, and S. R. Russell "noticed that eval could serve as an interpreter for LISP, promptly hand coded it". Shells, Tcl, the Python prompt and every browser's JavaScript engine start by interpreting.

What it is. An interpreter carries out a program directly instead of first translating the whole of it into machine code. Interpreting trades speed for immediacy: there is no build step, errors point at the source line, and code can be changed while it runs, which is why command languages are interpreted. Python's own glossary puts the distinction carefully: Python "is an interpreted language, as opposed to a compiled one, though the distinction can be blurry because of the presence of the bytecode compiler", which means that source files "can be run directly without explicitly creating an executable".

Where it came from. John Backus listed Mauchly's Short Code of 1950 among the early systems his FORTRAN group had not known; it ran on the UNIVAC by interpretation. The most famous interpreter was an accident: John McCarthy wrote the Lisp function eval for a paper, and S. R. Russell "noticed that eval could serve as an interpreter for LISP, promptly hand coded it". McCarthy also noted the cost of an interpreter that arrives early: "the unexpected appearance of an interpreter tended to freeze the form of the language", including choices he had made lightly, such as using zero for the empty list.

Command interpreters. Every shell is an interpreter. The GNU Bash manual opens: "Bash is the shell, or command language interpreter, for the GNU operating system", its name an acronym for the "Bourne-Again SHell", a pun on Stephen Bourne, author of the direct ancestor of the Unix shell; the current manual is Edition 5.3 of 18 May 2025. Tcl, the language of F5's iRules, and the interactive Python prompt, which lets you "enter statements and expressions at the interpreter prompt, immediately execute them and see their results", work the same way: read a line, run it, wait for the next.

Most interpreters do not walk the source. Modern interpreters first compile the program to bytecode and interpret that. CPython compiles each module to bytecode for a stack machine (its dis module shows it); Lua's first implementation of July 1993 already translated programs into instructions for a stack-based virtual machine run by a simple interpreter, and Lua 5.0 moved in 2003 to a register-based one; V8's Ignition interprets register-machine bytecode before the just-in-time (JIT) tiers take over. The interpreter's loop (fetch an instruction, dispatch on its opcode, execute it) is a small processor written in software.

Why interpreters are a security subject. An interpreter runs whatever text reaches it, which is the root of injection. Shellshock, Common Vulnerabilities and Exposures (CVE) identifier CVE-2014-6271 (published 24 September 2014), was Bash itself: "GNU Bash through 4.3 processes trailing strings after function definitions in the values of environment variables", so a crafted environment executed arbitrary code through vectors such as the ForceCommand feature of OpenSSH's sshd and the Apache HTTP Server's mod_cgi and mod_cgid modules. Log4Shell, CVE-2021-44228 (published 10 December 2021), showed the same pattern in a library that was not meant to interpret anything: in Apache Log4j2 2.0-beta9 through 2.15.0, an attacker who controlled log messages could make the Java Naming and Directory Interface (JNDI) lookups execute arbitrary code loaded from Lightweight Directory Access Protocol (LDAP) servers "when message lookup substitution is enabled"; 2.15.0 disabled the behaviour by default and 2.16.0 removed it.

Inside the loop. Lua's authors describe the machinery plainly. Their compiler uses no intermediate representation and "emits instructions for the virtual machine 'on the fly' as it parses a program". At run time, when the main interpreter loop executes a call, it "creates a new slot in the stack, adjusts several pointers, and continues the loop with the instructions of the called function", and a return removes the slot and continues with the caller, which, the authors note, is "not by coincidence" exactly what a real processor does to perform function calls. An interpreter is, in that sense, a processor whose machine code is the bytecode and whose registers are variables of a C program. Network engineers meet the same design in configuration languages: F5 documents its BIG-IP iRules as a "Tcl-based programming API for data-plane traffic", interpreted inside the traffic path.

What goes wrong. Beyond injection, the interpreter is itself a large program, often written in C, with its own memory-safety bugs; a sandbox built inside an interpreter is only as strong as that program. Interpreted code is slower for tight loops, which is why hot paths move to native extensions or a JIT. And the interpreter's version matters: bytecode and behaviour can change between releases, so a script tested on one interpreter can break on another.

Neighbours. The interpreter sits beside the compiler as the other way to run a programming language, usually works on bytecode, hands hot code to a JIT compiler, and appears to users as a shell or a REPL (read-eval-print loop). Brazilian practice says interpretador.

Also known as: interpreted language, interpretador, linguagem interpretada

Sources

← Back to I Back to the glossary