What is the purpose of a compiler?

Had your computer crash on you, or a website shows wrong, or your printer went dead on you? Come on in...

Moderator: Crew

User avatar
Zyx
Pretender to the throne
Posts: 1907
Joined: Wed Mar 29, 2006 20:48
Location: Helsinki
Contact:

What is the purpose of a compiler?

Post by Zyx »

Recently I was asked a question about how to explain what a compiler is.
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".
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:

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ää.
Do you has what it takes to join the Homestarmy? The guts? The determination? The five bucks? Join today!
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

I got a little interested in the topic and found myself yesterday immersed in the magical world of kernels, hardware abstraction layers and similar stuff, eventually finishing as far as reading how teleprinter works. I don't understand a half of what I read, regardless of language I read article in, but I noticed that even experts don't fully understand the nature of this all. Anyway, it's an interesting world, full of exciting mysteries.
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

The friend who asked me the question also asked our common friend who is psychologist, so he has extensive knowledge about compilers (seriously, he is psychologist, but also codes in free time and is interested in various topics like cognitive psychology etc.). Anyway, what he said is that the first ever compiler was simply coded in machine language (according to Wikipedia the first ever compiler is A-0 System). Whether next compilers were also coded in machine language or used the technology of the first compiler I don't know, and I have no real desire nor time to dig the subject deeper. Anyway, these entries may be useful:

http://en.wikipedia.org/wiki/History_of ... nstruction
http://en.wikipedia.org/wiki/FLOW-MATIC
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

"Here is something to consider: If you open up a basic text-editor like notepad and click 10 keys on your keyboard, then save the file. It will be a file made up of a series of 80 ones or zeros, each one or zero physically made up of a circuit being on or off. Each letter, number or other character you type is simply an 8-digit binary number up to 8 digits.

Programmers have to code this way, even though it is less efficient in binary terms, because it is easier on the programmer. He can remember a word like 'if' easier than a string like 0101011101000110 even though that isn't optimal since the set of possible commands and the binary syntax could be much smaller, but that would require the programmer to be able to distinguish 0101011101000110 from 0101000101100110 or any other series (or the odd characters they would give you when not looking at them in binary) as well as he can distinguish a word like 'if' from another word like 'not'. So we create an inefficient syntax for the programmer to write in, but then at some point convert it into a more efficient binary representation for whatever purpose it is needed.

My point is, all the computer ever gets is the binary, all it saves is the binary. I don't think the idea that the text entered by a programmer is converted into more computer-understandable languages is exactly correct, at least not in a philosophical sense, because it implies the computer is able to understand something at that level. But it's a mechanical process through-and-through. It's just circuits being on or off, and simple mechanical instruments dumbly reacting to streams of binary data with little processing power. The compilers and conversions are just dumb processes that change one binary string or group of strings to another according to an algorithm which was designed by humans to get a binary string that when used as the input to a device gives the desired result.

I suspect human reliance on inefficient verbal language is symptomatic of one of the ways modern computers are superior to humans."

Reply from "the other" forum. Zyx knows what I talk about. :wink:

It's not that I expect a high activity in this topic in this very forum, but cut&paste technique doesn't harm anyone, certainly not anonymous internet users who may stumble upon this post here or over there. This is how knowledge spreads!
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
Zyx
Pretender to the throne
Posts: 1907
Joined: Wed Mar 29, 2006 20:48
Location: Helsinki
Contact:

Re: What is the purpose of a compiler?

Post by Zyx »

eMTe wrote:"Here is something to consider: If you open up a basic text-editor like notepad and click 10 keys on your keyboard, then save the file. It will be a file made up of a series of 80 ones or zeros, each one or zero physically made up of a circuit being on or off. Each letter, number or other character you type is simply an 8-digit binary number up to 8 digits.
This isn't actually true, one character can actually be multiple bytes, but that's nit-picking.
So we create an inefficient syntax for the programmer to write in, but then at some point convert it into a more efficient binary representation for whatever purpose it is needed.
It's not true that a programming language has to be "inefficient". In an Assembly language, each instruction maps exactly to one instruction to the processor. Basically the programmer writes "decrease value in register 1" which is the exactly same thing as "00000101" so no efficiency is lost. However, the modern computer architecture is so complex that working on such low level would be the same thing as (quoting Hofstadter) trying to look at DNA by atom by atom.
My point is, all the computer ever gets is the binary, all it saves is the binary. I don't think the idea that the text entered by a programmer is converted into more computer-understandable languages is exactly correct, at least not in a philosophical sense, because it implies the computer is able to understand something at that level.
Ah, but it is. In machine code, your instruction set mostly consist of doing stuff to memory or jumping to another instruction. Even a simple high level programming code "echo "Hello world."" has so many things that the processor does not understand or even care about. For the computer to understand the task of displaying "Hello world" on display, it's broken down to many simple instructions that have very little to do with displaying stuff on screen.
I suspect human reliance on inefficient verbal language is symptomatic of one of the ways modern computers are superior to humans.
I'll just leave this 64kb intro here. The computer is a big-ass calculator and is subject to the laws of mathematics. Saying that modern computers are superior to humans is the same as saying mathematics is superior to humans, but really, they are just our tools.
Do you has what it takes to join the Homestarmy? The guts? The determination? The five bucks? Join today!
Drasir-Vel
[insert custom title here]
Posts: 1484
Joined: Sun Jan 18, 2009 15:28
Location: Denmark

Re: What is the purpose of a compiler?

Post by Drasir-Vel »

Reminds me of this: http://anynowhere.com/linoleum
It's a programming language which "has an almost 1:1 source-to-CPU instruction ratio"

Also it reminds me of Noctis: http://anynowhere.com/noctis
A game which can fit an entire galaxy, with 78 billions of unique stars, each star having several unique planets. Each planet you can land on where physically possible and travel around on a huge surface area. It all fits into 1,7 MB thanks to it all being procedurally generated from a seed.
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

philosopher wrote:So we create an inefficient syntax for the programmer to write in, but then at some point convert it into a more efficient binary representation for whatever purpose it is needed.
Zyx wrote:It's not true that a programming language has to be "inefficient". In an Assembly language, each instruction maps exactly to one instruction to the processor. Basically the programmer writes "decrease value in register 1" which is the exactly same thing as "00000101" so no efficiency is lost.
""decrease value in register 1" is a 28-character command. At a byte per character, that would give us a 224 digit binary number not an 8 digit one. To open up a text-editor and write that code and then have it "mapped to" a single byte is the kind of conversion to which I referred.

A more efficient system would be to go in and write a single character instead of any given 28-character command which represents a single byte of data according to some conversion mechanism. Needless to say, human beings are not capable of such efficient communication namely because of the very different way our memory works, such as that is is much more vague but much more powerful for many practical 'intelligent' applications."
philosopher wrote:My point is, all the computer ever gets is the binary, all it saves is the binary. I don't think the idea that the text entered by a programmer is converted into more computer-understandable languages is exactly correct, at least not in a philosophical sense, because it implies the computer is able to understand something at that level.
Zyx wrote:Ah, but it is. In machine code, your instruction set mostly consist of doing stuff to memory or jumping to another instruction. Even a simple high level programming code "echo "Hello world."" has so many things that the processor does not understand or even care about. For the computer to understand the task of displaying "Hello world" on display, it's broken down to many simple instructions that have very little to do with displaying stuff on screen.
"You seem to be contradicting yourself. Are you saying the computer actually understands -- in the philosophical sense -- what it is doing or are you agreeing with me that it does not and if anything it is less like the human-like consciousness required to have understanding in a philosophical sense at that lower-level."
Zyx wrote:I'll just leave this 64kb intro here. The computer is a big-ass calculator and is subject to the laws of mathematics. Saying that modern computers are superior to humans is the same as saying mathematics is superior to humans, but really, they are just our tools.
"Interesting video and contest. I didn't say computers were superior to humans in general and I'm not sure what that would even mean. I said that efficient communication is one of the ways in which computers are better than humans. Solving math equations is another. There are plenty of ways in which humans are superior to computers. Philosophically speaking, I think we can agree that saying anything is superior to something else without qualification at least implicit qualification is nonsense. Indeed, any superiority can be reversed by using the inverse qualification. If Joe is superior in tallness to Jane, then Jane is superior to Joe in shortness."
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
Zyx
Pretender to the throne
Posts: 1907
Joined: Wed Mar 29, 2006 20:48
Location: Helsinki
Contact:

Re: What is the purpose of a compiler?

Post by Zyx »

eMTe wrote:A more efficient system would be to go in and write a single character instead of any given 28-character command which represents a single byte of data according to some conversion mechanism. Needless to say, human beings are not capable of such efficient communication namely because of the very different way our memory works, such as that is is much more vague but much more powerful for many practical 'intelligent' applications."
As it happens, there is the aptly-named f***. Eight one byte-length instructions. I would not say that it's really that powerful language, yet everything is possible in it.
philosopher wrote:"You seem to be contradicting yourself. Are you saying the computer actually understands -- in the philosophical sense -- what it is doing or are you agreeing with me that it does not and if anything it is less like the human-like consciousness required to have understanding in a philosophical sense at that lower-level."
I probably shouldn't have used the verb "understand". What I meant by it was that the processor mostly just modifies its memory as instructed by the program. It's an arithmetical engine, there is no sentience or no understanding. What I meant was that languages like f*** and Assembly do not introduce any concepts (like "print to screen") that are beyond these memory operations, which most other higher level languages reduce the code into.
Do you has what it takes to join the Homestarmy? The guts? The determination? The five bucks? Join today!
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

Zyx wrote:"understand"
What I can advise myself - never use this word (as well as a couple of other words) when talking with philosopher or "humanist" in general. They love to play with such words like children in the sandbox.
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

Zyx wrote: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.
I am almost sure this is the explanation of what is consciousness.

Basically, consciousness works similarly to program errors. Human body can be understood as Data. Cells, body fluids etc. but instructions how they should operate is also Data. But sometimes computer (you) begins to analyse its own existence (gains access to read-only section of Data) instead of "just living" (gaining access to operating instructions). These "errors", on a humane level can be applied to philosophers, artists, poets.

The problem is, if consciousness works similarly to computer program errors something was overlooked either regarding us, humans, or computers.
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
Zyx
Pretender to the throne
Posts: 1907
Joined: Wed Mar 29, 2006 20:48
Location: Helsinki
Contact:

Re: What is the purpose of a compiler?

Post by Zyx »

There's a good book on this subject, Gödel, Escher and Bach, which tries to through mathematics and AI research explain how from DNA there suddenly becomes a consciousness. Not in those terms, but the book is a bit hard to explain.

Making parallels with software/hardware and consciousness/brain is easy to do. However, we have lots of limits on our self-reflection. It's true that to some extent we can analyze our selves, but you can't go really that deep how your brain works. You can easily analyze a machine and software and see how they work. We know pretty well how DNA and our hardware works, but we have zero access to what goes in our brain on low level.
Do you has what it takes to join the Homestarmy? The guts? The determination? The five bucks? Join today!
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

Yes, somebody once recommended me this book via Facebook. I must read it someday, unless I will decide that what can be found in it was already discovered 2000 years ago by a couple of weirdos and by 100 millions of people during last three days. ;)

The problem with making parallels is unavoidable, because conscious and intelligent humans so far act/think in a similar manner to computers/machines. The magic words are "system", "mechanics", "order" etc. So far nobody proved, neither on logical or metaphysical ground that true chaos (understood as something totally random, undescribable and out of grasp) exists, simply because he is conscious/self-aware. Probably the only humans who can be considered atm "chaotic" in a scientific/linguistic manner are mentally disabled people, all these rainmans etc. So "chaos" simply equals to "unconsciousness", because when you are mentally disabled you are unable to put anything into the proper box and add proper social value to it.

Btw, WE PEOPLE know what happens on OUR brain level. Human brain isn't free from Mendeleyev's table. Your brain is more complex than the chair you sit on when you read this post and the landscape outside your window, but it operates in the same way.

I am always amazed how you people from The North can make such posts at the high noon. We people from The South usually cure coathangers at this time. ^^

On a sidenote that should please Scythe, I begin to think that the whole consciousness/self-awareness/language thingy leads humankind to ultimate self-euthanasiation. On the other hand, rocks and trees will survive, simply because they don't give a damn.
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
Maz
Admin emeritus
Posts: 1938
Joined: Thu Mar 16, 2006 21:11
Location: In the deepest ShadowS
Contact:

Re: What is the purpose of a compiler?

Post by Maz »

You knew I couldn't resist this topic, right? Luckily I'm using mobile and thus leave this short now. Zyx is not 100% correct when hes stating everything is just data. Modern (and also not so modern) separate data and code in memory, thus executing data is prevented. Compiler is also responcible from deciding which is data and which is code...
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

If not everything is data then you're not Finland.
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

From a philosophical standpoint, the first thing to be aware of is that everything is Process. Both Process (an MP3 file for example) and a program (Firefox browser) are Processes and stored in God's Memory (not to be confused with storage, like human memory) indistinguishable from each other. This is called Universe, after the genius (God) who came up with a lot of really great stuff. This is also why viruses (Finns) and other hacks (Poles) are possible and why programs (wars) sometimes crash (holocausts). The computer (human) is fooled to execute data as a program when [here it begins to float so don't execute the data] they accidentally or on purpose read Space from Time.

In essence, what a compiler (metaphysics) does is translate a piece of data (human thought) that somewhat resembles English (Universe) to instructions (fundamental forces) for a computer (human) to do things (computer). 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 (the poetry is wind) 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. /general blah blah/

"is beyond me." does no need

The closest programming language to the "metal" is Assembly language

I'd say rocks and trees

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.

How it happens is way beyond my understanding.
How it happens is way beyond my understanding.
How it happens is way beyond my understanding.
How it happens is way beyond my understanding.

Maybe it isn't supposed to be understood?
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

Forgetting the last post, I returned (or better to say, certain discussion prompted me to return) to reading more about those magical thingies like machine code, abstraction layers, data abstraction etc. I understand more, but I also have this uneasy feeling that Wikipedia articles which I encountered on my journey changed since last year which makes me conclude that I am not the only one who tries to understand how does it happen that all these magical tiny symbols called numbers and letters all of a sudden become translatable to raw operations and the other way around. Well, that's only good.
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

https://en.wikipedia.org/wiki/Abstraction_layer

The articles become shorter, but it doesn't mean they become more understandable.

"abstraction layer is a way of hiding". Ok. So, what's the "way of hiding"? Sounds like one of Sun Zi's art of war paragraphs.

The article is fun, because it introduces even more enigmatic terms like "implementation detail", "particular set", "generalization of a model" or "level of indirection". My English hasn't gotten better over the years, but I can still sense that this area of computer science is particularly odd. In the same time we face the very basics of computer architecture which is (the computer as a machine) really formal and mathematical and we also face the philosophical/humane understanding of this area and this side of the river is full of shrubs and undergrowth.

What's the link between formal logic and chaotic, irrational human behaviour, Zyx? Do we know more now?
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
Zyx
Pretender to the throne
Posts: 1907
Joined: Wed Mar 29, 2006 20:48
Location: Helsinki
Contact:

Re: What is the purpose of a compiler?

Post by Zyx »

What's the link between formal logic and chaotic, irrational human behaviour, Zyx? Do we know more now?
The never-ending fight against entropy and chaos. Computers and logic systems are created by humans and have certain assumptions about their existence that set limits but also mean that everything is perfect - 1+1=2 always. The humans, on the other hand, live in the reality that is. We don't know the limits, and according to some logical arguments, we can't ever know what the assumptions in our reality are because we are within the system and that would require looking outside in.

But humans are not irrational, they might seem like it. We're not perfectly rational and we make mistakes. I don't even know what irrational behavior would be. I mean, if you decide everything based on a dice throw, that's still rational as you follow (an insane) rule - it can be understood. Irrational usually just means that we're not aware what the rational behind some actions were, not that it doesn't exist.
Do you has what it takes to join the Homestarmy? The guts? The determination? The five bucks? Join today!
User avatar
eMTe
Cyberflaneur
Posts: 6990
Joined: Wed Mar 08, 2006 23:08
Location: Cracow

Re: What is the purpose of a compiler?

Post by eMTe »

Zyx wrote:Computers and logic systems are created by humans
This is actually not true, because humans created this quite fun assumption that everything is a logic system.

So, if logic system was BEFORE humans then humans are the product of a development of logic system. So, the logic system created logical creatures which talk about logic and they follow formal rules which are already formal, because everything is logical and formal.

Of course this all happens in obscure hamlet, in the middle of England and the author is gay.
Zyx wrote:perfectly rational
Perfectly rational supposition creates natural linguistic antynomies/multipolarities that there's something imperfectly rational or perfectly irrational or imperfectly irrational.

But this is all philosophy thus it's pointless vodka talk.

You didn't answer my question, what is abstraction layer. 8)

"set of functionality", this is my fav part of the entry. Only I'm sceptical that these functionalities are hierarchical. There aren't any "layers", onion-like.

More likely, the abstractions are constructed in a form of vegetable soup. Like, there's a lot of water, but also there are potatoes, tomatoes etc. Various functionalities perform certain functions, but it is we, humans, who by this and not another one, complexity of our bodies and by this and not another one complexity of our mean of interaction with outside world, created hierarchies. The soup became an onion.

Processor, memory, external devices, they are all important and can't live without themselves, like ebony and ivory, like white collar without blue collar, but they are still treated separately, because we, being part of the abstractions, are treated as abstractions by the rock/tree world. We're abstractions for rocks and trees after all, aren't we? Sure, we're the ones capable of viewing plants as belonging to different (lower) orders of existence, but who said that INCAPABILITY of viewing humans as belonging to higher order is not part of certain order?

Interesting things, this all.
"As you have noticed over the years, we are not angry people." (itebygur)
User avatar
Zyx
Pretender to the throne
Posts: 1907
Joined: Wed Mar 29, 2006 20:48
Location: Helsinki
Contact:

Re: What is the purpose of a compiler?

Post by Zyx »

I think this insane thing of doing Tetris on Conway's Game of Life has some ideas about abstractions.
Do you has what it takes to join the Homestarmy? The guts? The determination? The five bucks? Join today!
Post Reply