Compiler Writing

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
1382

Compiler Writing

Post by 1382 »

Would it be possible to write a compiler entirely in C?
Jamethiel

RE:Compiler Writing

Post by Jamethiel »

Oh, sure. Absolutely. No problem.
Zhen Lin

RE:Compiler Writing

Post by Zhen Lin »

Just make sure you have a C compiler to compile it with. (Chicken and Egg)

GCC is completely written in C. But you can't compile it without GCC...

Why don't you use GCC instead? Modifications to BFD should be sufficient if you have a different ABI and ELF.
CarbonBased

RE:Compiler Writing

Post by CarbonBased »

It's even easier to modify LCC to suit your needs (afterall, that's basically what it's designed for).  Specifically version 3.6.  4.0 is a better compiler, but not as well documented (there's an entire book (written by the authors of the compiler) dedicated to using, porting, and retargetting LCC 3.6)

I've modified 3.6 to use nasm as the assembler backend, and RDOFF as the object output.  It took all of about half an hour :)

Cheers,
Jeff
Mara

RE:Compiler Writing

Post by Mara »

I have one question. Is the compiler that you want to write  dedicated to run under your own os or an amator's one, or it should run under LINUX or BeOs for example!!!!!
1382

RE:Compiler Writing

Post by 1382 »

This is to be run under my own OS.
CarbonBased

RE:Compiler Writing

Post by CarbonBased »

My port of LCC is designed to run under my OS, eventually, but for the time being it runs under Linux (and should run under any OS, as long as nasm exists).

Jeff
Mara

RE:Compiler Writing

Post by Mara »

All is OK. You should start by writing the libs and the header files that you intend to use using assembly or c itself, then start programming!
Now all depends on the executable file format that your os is using.
Have you ever written an compiler?
1382

RE:Compiler Writing

Post by 1382 »

No, actually I haven't even written one line of the operating system, I just wanted to know 'bout the languages I can use.  Thanks for you issuing the information anyway.
Post Reply