Open In App

Introduction to Interpreters

Last Updated : 10 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – Assembler, Compiler, and Interpreter 

All high-level languages need to be converted to machine code so that the computer can understand the program after taking the required inputs. The software by which the conversion of the high-level instructions is performed line-by-line to machine-level language, other than compiler and assembler, is known as INTERPRETER

The interpreter in the compiler checks the source code line-by-line and if an error is found on any line, it stops the execution until the error is resolved. Error correction is quite easy for the interpreter as the interpreter provides a line-by-line error.  But the program takes more time to complete the execution successfully. Interpreters were first used in 1952 to ease programming within the limitations of computers at the time. It translates source code into some efficient intermediate representation and executes them immediately.

Interpreters

 

Source programs are compiled before time and stored as machine-independent code, which is then linked at run-time and executed by an interpreter. An Interpreter is generally used in micro-computers. It helps the programmer to find out the errors and to correct them before the control moves to the next statement. The interpreter system performs the actions described by the high-level program. For interpreted programs, the source code is needed to run the program every time. Interpreted programs run slower than the compiled programs. 

Self-Interpreter is a programming language interpreter which is written in a language that can interpret itself. 

For Example: BASIC interpreter written in BASIC(Beginner’s All-purpose Symbolic Instruction Code). They are related to self-hosting compilers. Some languages have elegant self-interpreters such as Lisp and Prolog. 

Need for an Interpreter

The first and vital need of an interpreter is to translate source code from high-level language to machine language. However, we already had the compiler to serve the purpose, the compiler is a very powerful tool for developing programs in a high-level language. However, there are several demerits associated with the compiler. If the source code is huge in size, then it might take hours to compile the source code, which will significantly increase the compilation duration. Here, the Interpreter plays its role. The interpreter can cut this huge compilation duration. As they are designed to translate single instruction at a time and execute them immediately. So instead of waiting for the entire code, the interpreter translates a single line and executes it. 

Advantages and Disadvantages of Interpreters

  • The advantage of the interpreter is that it is executed line by line which helps users to find errors easily.
  • The disadvantage of the interpreter is that it takes more time to execute successfully than the compiler.

Applications of Interpreters

  • Each operator executed in a command language is usually an invocation of a complex routine, such as an editor or compiler so they are frequently used to command languages and glue languages.
  • Virtualization is often used when the intended architecture is unavailable.
  • Sand-boxing
  • Self-modifying code can be easily implemented in an interpreted language.
  • Emulator for running Computer software written for obsolete and unavailable hardware on more modern equipment.

Some examples of programming languages that use interpreters are Python, Ruby, Perl, PHP, and MATLAB. 

Top Interpreters According to the Computer Languages

  • Python- CPython, PyPy, Stackless Python, IronPython
  • Ruby- YARV, Ruby MRI (CRuby)
  • JAVA- HotSpot, OpenJ9, JRockIt
  • Kotlin- JariKo

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads