Can a processor understand programming languages?

Programming books sometimes indicate that the CPU does not understand the C ++ language (or any high-level programming language). All C ++ statements must be converted to machine code before they are executed. But who does the translation?

Oh, this is not a secret, they say; the translation is performed by a compiler, which itself is a computer program. But in this case, the computer performs the translation.

This seems to me an insoluble paradox. The CPU (the "brain" at the heart of the computer) does not understand the word C ++, but it does the translation between C ++ and its own internal language. Isn't that a contradiction?

+4
source share
1 answer

Most of the answer is this: C ++ source code (or any high-level programming language) is stored in a text file, just as you can save an essay or note. But text characters are stored in numerical form. Therefore, when the compiler works on this data, it performs another form of crunching the number, evaluating the data and making decisions in accordance with exact rules.

If this is not clear, imagine: you have a task to read letters from a person who knows Japanese, but not English. You, meanwhile, know English, but not one Japanese word.

But suppose you have a training book that describes how to translate Japanese characters into their equivalent in English. The instruction book is written in English, so you have no problem using it.

So, even if you do not understand Japanese, you can translate all the Japanese you want by carefully following the instructions.

Here's what a computer program is: an instruction book read by a processor. A computer program is an inert thing β€” a sequence of instructions and data, but β€œknowledge” inside a computer arises from its programs. Programs allow the computer to do all kinds of smart things, including translating a text file containing C ++.

The compiler, of course, is a very special program, but what it does is not at all strange or impossible. Like a computer program, its "study book" as described. What he says, how to do this, is to read a text file containing the source code in C ++ and print another book statement: This output is your C ++ program in executable form.

The very first compilers should have been written to machine code. Later, old compilers could be used to write new compilers ... so even experienced programmers could rely less and less on machine code through the boot process.

+13
source

All Articles