Archived

This topic is now archived and is closed to further replies.

Programming language programming language

This topic is 5151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I were to fully develop an implementation of C (that is, build a C compiler that will compile C code into an executable) by using QBasic, for example; how would that differ from developing a C compiler in C itself? I know the essential differences, but I am unsure of the following. What if I build a special version of C compiler in QBasic. Now I have a C-esque compiler that works ONLY under DOS or Windows, on an IA-32 platform. This compiler, however, generates code that will work on any processor, theoretically, just as C does (no official specific OS support, except in special libraries). Now what if I take my special-C compiler (that I made in QBasic) and design a special-C compiler, in itself. If special-C was portable (unlike QBasic), and I designed a compiler in it, wouldn''t I then break away from the restrictions of QBasic? Would there be any negative effects carried over from the former generation of the special-C compiler built in QBasic? Again: I build a special-C compiler in QBasic. Then I build another special-C compiler (the exact same one, more or less) in special-C. How would this work? Am I free from QBasic entirely, at this point? Of course, I am using these as examples. I simply want to know what would happen. I do not plan on using these languages, and I plan on implementing my own, custom language. However, I wanted to build the compiler, at first, in a more familiar language, even though it may or may not be the best there is to work with. Then I will rebuild the language in my own language. Am I now only limited to the restrictions of my custom language? I hope you understand what I mean. Thanks for any help.

Share this post


Link to post
Share on other sites
This is called bootstrapping a language. Basically, yes: you write two compilers, one in a different language, and one in your language. Compile the foreign one, then use it to compile the native one. Sometimes then use the native one to recompile the native one. (fun details)

Share this post


Link to post
Share on other sites
I would think that creating a new compiler would require knowing assembly code, and then parsing every line of your new compiler code & converting it into assembly. Then having some setup where you can convert the assembly into a binary, either with a third party executable, or...I don''t know. I doubt you''d be required to write 1''s & 0''s.
Hope this helps
~Slayemin

Share this post


Link to post
Share on other sites
There are no C implementations which generate code that will work on any processor. You're confused between the C specification and a C implementation. The C specification provides the necessary abstractions that will allow C source code to be portable across any conformant C implementation. So, C source code can theoretically work on many platforms, but code generated by a C implementation tends to work on the specific platform(s) that it targets.


[edited by - SabreMan on November 11, 2003 7:19:28 AM]

Share this post


Link to post
Share on other sites
Yes, you''d be free from QBasic at this point.

And congratulations if you came up with this scheme on your own. This IS how people write compilers for most new languages.

The original version of C (yes, real C used this technique a long time ago) was very limited, didn''t have any real type safety, or anything. A compiler was written in something (BCPL comes to mind, but I''m not sure) that was able to compile a similarly braindead version of C. Then it was a matter of expanding C''s features, using C. Because each version is a refined version of the previous code, all the code you just wrote to make this new version is still valid (more or less) code in the new version. C works really well for this since it''s basically just shorthand assembly.

By switching to the early C, as soon as possible, it ensured that the compiler would be written mostly once (only the original very limited version was written twice), and it also ensures they made a completely functional system. If anything didn''t work, they''d find it quickly, as they couldn''t write a compiler without whatever feature was missing.

Somewhere on the web (I downloaded it once) is the original C compiler. It won''t compile with a new compiler, too much has changed, but it''s readable... and it was only like 3 or 4 pages long.

Share this post


Link to post
Share on other sites
quote:
Original post by superpig
Aren''t there tools like YACC to help with that? I don''t really know much about them...

Lex and Yacc (and Flex and Bison) produce C code.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites