Question Many Experts Do Not Answer It To Me! Is It that Hard?

Reply

Join Date: Oct 2008
Posts: 33
Reputation: f.ben.isaac is an unknown quantity at this point 
Solved Threads: 0
f.ben.isaac f.ben.isaac is offline Offline
Light Poster

Question Many Experts Do Not Answer It To Me! Is It that Hard?

 
0
  #1
Nov 12th, 2008
I'm wondering, if compilers are written in human readable way, then how come the machine could read the compiler?

If machine could read the compiler - which is by itself is not a machine language, why don't the machine just read the high level programming language directly? As it is known, machine only can understand in binaries. If the compiler was written in binaries, in such a way that these binaries can fetch the high level language and translate it back to machine language, it would make more sense, but compilers are not in binaries, so there should be something else.

If a language needs a compiler, then how come a compiler is invented, since this compiler is a language and it will a compiler, see its confusing now!

A compiler is binary, so its been executed, so what compiled the compiler! And the compiler compiler's in what language was written?

I'm sure there are experts here who knows the answer. Waiting your reply.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Question Many Experts Do Not Answer It To Me! Is It that Hard?

 
0
  #2
Nov 13th, 2008
Originally Posted by f.ben.isaac View Post
I'm wondering, if compilers are written in human readable way, then how come the machine could read the compiler?

If machine could read the compiler - which is by itself is not a machine language, why don't the machine just read the high level programming language directly? As it is known, machine only can understand in binaries. If the compiler was written in binaries, in such a way that these binaries can fetch the high level language and translate it back to machine language, it would make more sense, but compilers are not in binaries, so there should be something else.

If a language needs a compiler, then how come a compiler is invented, since this compiler is a language and it will a compiler, see its confusing now!

A compiler is binary, so its been executed, so what compiled the compiler! And the compiler compiler's in what language was written?

I'm sure there are experts here who knows the answer. Waiting your reply.
Simple answer: When a program is written in C, Fortran, Pascal, Algol, Ada or any of a number of other languages, it must be compiled into machine-readable language before the machine can run it. The same goes for almost every compiler; it must be compiled into machine language before a machine can run it. Only a compiler written in machine language would need no translation and could be executed directly. And yes, this does mean that the first compilers, the first assemblers, the first OSen were written directly in machine language. (Actually, they might've been written in an assembler-like pseuo-language, assembled by hand and toggled into the machine using the front-panel switches. Look at pics of most any computer from before 1975 or so; you'll find that pert near all of them had front-panel switches for toggling in data and programs, and for running programs and stepping through memory.)

A compiler *is* a binary machine-language program; it translates a high-level language program into machine (binary) language. A well-written compiler is often used to compile itself. This, of course, introduces the 'chicken (compiler binary) or egg (compiler source)' quandary; but the clear answer is that the chicken must come first. There *must* be an initial compiler to translate the compiler source into machine language; once that boostrap process is complete, the compiler can prepare its own future versions (if it is well-written).

Take the C compiler. Originally, it was written in assembler which is easily translated to machine language. When it was (largely) rewritten in C, the 'assembler' compiler was used to compile it. At some point, the 'C' version became good enough to compile its own source. About that time, the assembler-source version was retired.

As a real-world example, in a class many years ago, I had to write a VAX-11 assembler. Unbeknownst to the professor, I had access to a VAX where I worked at a co-op job. [Note, I no longer remember what I wrote it in, but I'll say VAX-11 Macro (assembler) for the purpose of this illustration.] When it was time to turn it in, it was producing *exactly* the output listing that DEC's assembler produced. A couple more weeks and I would've been able to generate proper binary output suitable for linking. Had I gotten to that point and had my assembler actually produced correct binary, I would have been able to use my assembler (binary) to assemble, you guess it, my assembler (source). And the two versions (Macro-32-assembled and MyOwn-assembled) would have produced identical output *if* I programmed it correctly. (FWIW, even though my assembler produced no binary output, I still got an 'A' on the project because my assembler's output listing showed that it correctly handled all of the labels, instructions and addressing modes available on the VAX; from there, producing linkable binary would've been trivial.)

Prolly more than you wanted to know, but I hope I adequately answered your question.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 33
Reputation: f.ben.isaac is an unknown quantity at this point 
Solved Threads: 0
f.ben.isaac f.ben.isaac is offline Offline
Light Poster

Re: Question Many Experts Do Not Answer It To Me! Is It that Hard?

 
0
  #3
Nov 13th, 2008
Well Answered....MANY THANKS! Even though, i did not understand fully the extra part you were talking about, but i got the gist....Good explaination
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Question Many Experts Do Not Answer It To Me! Is It that Hard?

 
1
  #4
Nov 13th, 2008
You're referring to the compiler bootstrapping process, which is a sort of chicken and egg scenario. The gist of it is that early compilers/assemblers were written in machine code in a very basic form, then used to compile more complex compilers. Nowadays there are usually more sophisticated methods for bootstrapping compilers, such as using a different platform with an existing compiler to cross-compile to your target platform. Because of this, you'll find that a lot of compilers are actually written in the language that they compile (for example, ghc is written almost entirely in Haskell). You can read more about this on the web:

http://en.wikipedia.org/wiki/Bootstrapping_(compilers)
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,474
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: Question Many Experts Do Not Answer It To Me! Is It that Hard?

 
0
  #5
Nov 13th, 2008
compiler high level language and machine language is like: English man Swahili man and one who knows both swahili and english. The one writes a paper in english and the compiler: who now knows both language takes that written and translate it all into swahili language. Then when took to any swahili speaking man can read that script. that english is HIGH LEVEL LANGUAGE and swahili is MACHINE LANGUAGE and translator of script is COMPILER

Hope you can understand now!
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 36
Reputation: fuzzyduq is an unknown quantity at this point 
Solved Threads: 0
fuzzyduq fuzzyduq is offline Offline
Light Poster

Re: Question Many Experts Do Not Answer It To Me! Is It that Hard?

 
0
  #6
Nov 13th, 2008
Hi,

While the above responses are correct, I think they have missed one signifcant point. The reason for compilers is speed. Speed for both programming, and speed for for program execution.

If all programs were written in machine code using binary, they would take a very long time to write, as the programmer would have to do the translation themself. While effective, this, of course, would be incredibly inefficient from a time and/or resource cost perspective.

Further, while it is possible for the computer to read the source code directly, and therefore translate the source code into executable code, this is not the only function of the compiler. The compiler also checks the source code for obvious errors which would prevent the program from running, such as incorrect syntax, spelling errors (of control and/or command words), ensuring all if statements, especially nested ifs, have the correct end, etc., which the programmers often overlook, despite vigilant proofreading. I know this well, as I have programmed since the early 1970's in a number of languages, and I have proofread not only my own programs and documentation, from business analyses to business/program specifications to source code to user manuals, but those of others as well.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,474
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: Question Many Experts Do Not Answer It To Me! Is It that Hard?

 
0
  #7
Nov 16th, 2008
Good Job!
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the IT Professionals' Lounge Forum


Views: 698 | Replies: 6
Thread Tools Search this Thread



Tag cloud for IT Professionals' Lounge
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC