Introduction to Interpreters
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. If an error is found on any line, the execution stops till it is corrected. This process of correcting errors is easier as it gives line-by-line error but the program takes more time to execute 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 immediately execute this.
Source programs are compiled ahead of 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 computer. It helps the programmer to find out the errors and to correct them before control moves to the next statement.
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 which can interpret itself.
For Example- BASIC interpreter written in BASIC. They are related to self-hosting compilers. Some languages have an elegant and self-interpreter such as Lisp and Prolog.
Need of an Interpreter :
The first and vital need of an interpreter is to translate source code from high-level language to machine language. However, for this purpose Compiler is also there to satisfy this condition.
The compiler is a very powerful tool for developing programs in 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, Interpreter plays its role. They can cut this huge compilation duration. They are designed to translate single instruction at a time and execute them immediately.
Advantage and Disadvantage of Interpreter :
- Advantage of interpreter is that it is executed line by line which helps users to find errors easily.
- Disadvantage of interpreter is that it takes more time to execute successfully than 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.
- 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 Phyton, Ruby, Perl, PHP and Matlab.
Top Interpreters according to the computer languages –
- Phyton- CPhyton, PyPy, Stackless Phyton, IronPhyton
- Ruby- YARV, Ruby MRI (CRuby)
- JAVA- HotSpot, OpenJ9, JRockIt
- Kotlin- JariKo
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.