what is an interpreter in programming

11 months ago 18
Nature

An interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program). It generally uses one of the following strategies for program execution:

  • Parse the source code and perform its behavior directly;
  • Translate source code into some efficient intermediate representation or object code and immediately execute that).

An interpreter usually consists of a set of known commands it can execute, and a list of these commands in the order a programmer wishes to execute them. Each command (also known as an Instruction) contains the data the programmer wants to mutate, and information on how to mutate the data).

In contrast to an interpreter, a compiler takes an entire program and converts it into object code, which is typically stored in a file. The object code is also referred to as binary code and can be directly executed by the machine after linking. Examples of compiled programming languages are C and C++. Examples of interpreted languages are Perl, Python, and Matlab.

Some differences between interpreters and compilers are:

  • Interpreters translate code written in a high-level programming language into machine code line-by-line as the code runs, while compilers translate code from a high-level programming language into machine code before the program runs.
  • Interpreters usually take less time to analyze the source code, but the overall execution time is comparatively slower than compilers. Compilers usually take a large amount of time to analyze the source code, but the overall execution time is comparatively faster than interpreters.