What is an interpreter, the robot that reads your code? How do interpreters compensate for the shortcomings of compiler systems?

W

In this blog post, we’ll explain what an interpreter is and how it compensates for the shortcomings of compiler systems.

 

People who learned to program often joke that ‘computers are lazy and stupid’. Not only will a computer never do something you don’t tell it to do, but even if you do, it will only do it if you tell it to do it in machine language, a language of zeros and ones that it understands. Because of this, when we ask a computer to do something, we need a machine to translate the programming language we use into something the computer can understand. For many programming languages, this is done by a program called a compiler, which takes the code written in the programming language and turns it into machine language. But there’s a big problem with compilers: because they convert code in its entirety, if it’s not perfect, they don’t convert it at all. Many programmers who have written huge chunks of code only to have the compiler fail because of a small typo wanted a more programmer-friendly translation system, and the result is the interpreter.
The role of an interpreter is very similar to that of a parent reading a book to a child. When a parent reads to a child, there are often difficult words that prevent the child from understanding the text. Sometimes the parent has to explain the difficult words in a simplified way so that the child can understand them. After this process is repeated, the sentences become long and strange, but the child is able to understand them and move on. The interpreter, like a parent reading a book to a child, takes the code and breaks it down into sentences that the computer can understand, sentence by sentence.
The interpreter first teaches the computer some basic functions in machine language. For example, “DEF(x, y) is a function that stores the value of y in x”. It’s like teaching a child some very simple words. Once that’s done, the interpreter starts taking code from the programmer, sentence by sentence, and converting it into the functions it taught. If the programmer typed “x = 2 + 3,” the interpreter would turn that code into a combination of the functions you taught the computer, such as “DEF(x, SUM(2, 3)),” and pass it to the computer. In other words, an interpreter consists of a translator that converts the existing programming language into a combination of predefined functions and a simple compiler that turns the combination of functions into machine language.
Interpreters were invented to compensate for the shortcomings of the compiler system described above, and they have several advantages over compilers. The main one is that they translate code sentence by sentence, which saves you time fixing code or trying out programs. If you use the analogy of reading a book again and make a mistake in the middle of the book, a compiler would read the book from the beginning, whereas an interpreter would just correct the wrong sentence and continue reading. It also has the advantage of running as soon as you type, so it takes up less memory during execution. However, compared to compilers, interpreters have an additional step of converting code into functions, which is repeatedly executed every time the program is run, so the execution time after the code is complete is less efficient than compilers.
As mentioned above, interpreters are a great complement to the shortcomings of traditional programmers in the development process, and since you can program sentence by sentence, as if you were having a conversation, programming languages that use interpreters are often used for education and introductory programming. I hope that interpreter will help many people get over their fear of programming and enjoy the experience of talking to a computer.

 

About the author

Blogger

I'm a blog writer. I like to write things that touch people's hearts. I want everyone who visits my blog to find happiness through my writing.

About the blog owner

 

BloggerI’m a blog writer. I want to write articles that touch people’s hearts. I love Coca-Cola, coffee, reading and traveling. I hope you find happiness through my writing.