This is an interesting question, because I know next to nothing about compilers, those magical little things that make programs, well, programs. I mostly code in interpreted languages anyway. My answer was as follows:That we do not speak of wrote:[My friend] looking for a book (or maybe a set of articles, whatever) which explains to the layman how compilers work. The book can be in English (certainly not in Finnish ). Have in mind that he's a philosopher, so he's not really interested in a practical side (and maybe here lies his problem), he just wants to "understand" what means "to transform source language into target language".
From a philosophical standpoint, the first thing to be aware of is that everything is Data. Both data (an MP3 file for example) and a program (Firefox browser) are Data and stored in computer's Memory (not to be confused with storage, like hard drive) indistinguishable from each other. This is called Von Neumann architecture, after the genius who came up with a lot of really great stuff. This is also why viruses and other hacks are possible and why programs sometimes crash. The computer is fooled to execute data as a program when they accidentally or on purpose read Data from Memory from a wrong place.
In essence, what a compiler does is translate a piece of data that somewhat resembles English (a text file having source code in it) to instructions for a computer to do things. A while a go there was a nice Turing machine as Google's front page, which nicely illustrates some aspects of this. The paper is Data and the Computer reads the next icon and executes whatever is there and it has. However, here the memory and code are isolated from each other.
So, taking the Google Turing machine example the compiler coverts english sentences "read the next bit. if it's 0 go down" to symbols for the computer. Why this conversion does need to happen is beyond me. Probably because the CPU ultimately works on 0s and 1s and the compiler knows exactly the best order of those 0s and 1s so that the program as written (but, not necessarily, as intended) by the author runs best.
The closest programming language to the "metal" is Assembly language, which is literally just instructions to the CPU to read certain part of memory and jump to certain point of memory and write to certain point of memory. In Assembly language, each instruction from the programmer translates 1:1 to a operating instruction for the CPU.
In more traditional programming languages, I'm quite sure what the compiler does is to turn the semi-English sentences like (if x>0 then print "hello world") to operating instructions for the CPU. How it happens is way beyond my understanding.
The above probably has about 67 mistakes, spot them and win a cake*.
* Void where cakes are prohibited by law. Must have a Citizen watch to participate. Do not puncture, incinerate, or store above 250 degrees Celsius. Do not place near flammable or magnetic source. Ei saa peittää.