Talk to your car: how Your computer and phone know what You want them to do

What happens when You press the numbers in the calculator or type the message in the messenger? The young scientist Sergei Lisitsyn told how the translation from human language into machine, namely compilers, and how their work can help us to learn two languages or more.





What you need to know first of all the programming Languages and the programs written on them, into our life. According to various estimates, currently there are from two and a half to ten thousand programming languages, formal sign systems. With their help recorded a program — a set of steps that you must follow the car.

For any of our action in computer, tablet, and phone has many languages, which is strictly according to certain rules described everything that we potentially can make. And only a small part of these languages can communicate with computer directly, i.e., to interact directly with the machine code of zeros and ones.

For all other languages like C++ or Java need translators who will rewrite our program to computer understandable form. One of the varieties of such translators is called compiler.

Not surprisingly, the compilation and writing of translators — a science, is extremely relevant and versatile. Before the life of the programmers was heavy and clumsy: I had to write their programs in machine code, that is, the set of zeros or ones. He looked very bulky, it was extremely difficult to read, and especially to them. But to replace the native code came programming languages which is much easier to explain to the computer tasks. And for these languages, respectively, needed interpreters.

The first translator in the Soviet Union — or, as it was then called, PP, programming the program was written in 1954. Today translators are very different: free to download and edit (or open source) and paid that can not be correct.

 

To play the role of a compiler

To translate the program language to the computer language can be different. There is an option to take each line and explain it to the computer, however, it is often better to read the entire program, process it, make it more optimal for a computer to understand, and then take the form of machine code. The translators of the first type are called interpreters and the other compilers.

There are also many intermediate forms. To play the role of a compiler or interpreter easily, presenting himself as a translator, for example, from Korean to Russian. You can rewrite the text into another language, translating each sentence separately, and can completely read the book to understand it, to think about how another language will sound better whether those other means of expression. If your goal is to convey the basic idea, you can even do the extra in your opinion of the Chapter and called the characters other names. All depends on the translator tasks.





However, it is necessary to clarify another very important point. If you are a translator or interpreter, then every read transfer you to rewrite every line again. In other words, books on a shelf with the final translation from Korean language into Russian you have no choice.

In case you are diligent translator-compiler, the fruit of your labors — translation — is issued in a separate book, which can be put on the shelf, to admire, to wipe away the dust and get at any moment. Computer language this book, written in the language understood by the machine, called an executable file. However, if after reflection on the text, the author of the book that you translate, I decided to make a couple of suggestions or an extra comma, you will have to do it all over again: read a new book, to realize, to think and to put on the shelf next to the old translation of the new volume. Moreover, the two resulting work may not even differ, however, so it's definitely find out you will have to translate everything again.

 

Further — more What is inside the compiler, or work as professional translators? Conditionally, the compiler can be divided into three parts: frontend, middle-end and backend. Discuss in detail on each of them.

Frontend works directly with the language we want to translate the book. And it's insanely comfortable (later the reader will understand why). The compiler produces lexical, syntactic and semantic analysis. Speaking of books, there are sentences divided into words, is the predicate and the subject, the connection between the parts of a proposal and all other proposals.

Now imagine one more interesting thing. Let's say you translate a Korean book into Russian language, and nationality are you a Frenchman. Your task in the first stage is to test read Korean and translate it to French, which you prefer to work on. Returning to computers, the language in which the information presented in the compiler, as distinguished from the language of the executable file (book in Russian) and the language you want to translate (the book is in Korean). Such a language is called the language of the intermediate representation.

At the second stage — middle-end you in your native language (in our case French) thinking about and transform the text so that it became clearer, that is, performing the role not only of the translator, but the editor. If it's a magazine article, half of which consists of "water" on the stage of the middle-end of the translated French text, you remove all unnecessary and leave only the semantic component.

Is that you don't need to edit the author. Moreover, if you consider yourself not smart enough to tell him what you need and what is not, you can not edit the text at all. That is, the computer may not be optimized and no way to change the code of the author, translated into the intermediate representation can do this with some restrictions, and can — entirely at its own discretion. The best way depends on the situation.

Completely unoptimized code, especially written by beginners, it is often slow and inefficient. Therefore, some elements of optimization to input is recommended. But to fully optimize the code is also not always necessary — for example, in the C language where the programmer can dispose of the memory at its discretion, having regard to subsequent objectives: this is a factor that a computer cannot provide.





Finally, in the last part of the compiler in the backend, we transfer processed or stored version of the book with the French on the final language — Russian. Or, speaking to language of programmers, to translate from the intermediate language execution the language of the executable file. This executable file is saved independently of the original program in memory and can be run as many times as we wish.

 

Compilers as the essence of progress

The world is constantly created new and updated old languages. Continuously being improved and computer architecture — the way the machine perceives and reads the information. It turns out that any change in architecture or languages require to rewrite the compiler? No.

All this would require huge money and effort of programmers after each small change, and progress simply would not be able to walk at a pace. It is to circumvent this problem it is convenient to apply the above scheme of three stages. The fact is that when you create a new or revise an old language you need to write only the frontend the first stage, interacting directly with the language program and translates it into the language of the intermediate representation. After this action the other two parts, working with the intermediate representation and the language of the executable file, processes the code according to the same scheme as before.

Similar situation is in the case of architecture changes. As it is the last stage, the backend works with the translation from the intermediate representation to the final code that changes only part of it is enough for the compiler and earned under a different architecture. Returning to the analogy with literary translators, when learning a new language, such as Hebrew, it is enough to memorize the translation of all words from Hebrew to French and then to translate them into any other language. This is very convenient. This was the situation faced anyone with the experience of learning more than two languages.

Class scientific and technical problems is constantly growing, write new languages for old produced new standards are subject to constant changes in the architecture of the computer. All of this requires effort from programmers who write compilers. Optimization methods applied when improving the code at compile time, also constantly replenished by mathematicians. In the exchange of experience in computer science and open source projects, when any development is submitted for public review and can be freely used by all. In General, compilers strictly follow software and computers, and without them it is impossible the development of any computerized industry. published

Author: Sergey Lisitsyn

P. S. And remember, only by changing their consumption — together we change the world! ©

Join us in Facebook , Vkontakte, Odnoklassniki

Source: theoryandpractice.ru/posts/12435-compilers