C compiler

B

Bill Cunningham

How could one write the simplest C compiler possible. Like the one that
came in Unix V7? I guess some knowledge of binutils development would would
be needed right?
 
Ö

Öö Tiib

How could one write the simplest C compiler possible.
Like the one that came in Unix V7?
I guess some knowledge of binutils development would would
be needed right?

Simplest compilers typically translate already preprocessed code
to some lower language like LLVM or assembler. No optimizations
just one-to-one and no binaries just text-to-text.

There is no much point to write C compilers because there are
too lot of excellent open source C compilers available already.

Try to write things that are missing or are present but inconvenient.
If you are particularly interested in compilers and translators then
better write a translator from (subset of) some interpreted language
into C. Even if you can not ... then it is still better because we are
humans (cooperative) and so the questions that you ask when trying
to ... may raise interest of someone who can.
 
N

nikolaos.kavvadias

Hi,
How could one write the simplest C compiler possible. Like the one that
came in Unix V7? I guess some knowledge of binutils development would would
be needed right?

There exist lots of nice candidates. I myself have collected over the years, over 250 small compiler projects.

Some suggestions (just the first ones coming in mind):

- nwcc by Nils Weller
- pcc (revamped)
- the compiler projects at ftp://compilers.iecc.com
- plan9 compilers
- subc by Nils Holm (t3x.org)
- Lennart Augustsson's obfuscated compiler to ELF for x86 (otcc)
- smallc compilers (not ANSI/ISO C per se)
- tcc

There are many, many more, with varying level of ANSI/ISO C (89) support.

For a production-level compiler, I have three suggestions:
1) GCC
2) LLVM
3) COINS (search for COINS compiler infrastructure)

GCC and LLVM are the dominant open-source compilers. The latter one in the list is a real neglected jewel.


Best regards
Nikolaos Kavvadias
 
J

James Harris \(es\)

Hi,


There exist lots of nice candidates. I myself have collected over the
years, over 250 small compiler projects.

Do you know if any of them compile C to 16-bit with far pointers - at least
for data references? I am after one that will run on Linux. I have bcc but
it only supports short pointers.

James
 
J

Jorgen Grahn

Without wanting to say anything too heretical, I'm gonna take a peak
inside Stroustrup's text, where he talks about what he was trying to do
with C as he develops what becomes c++. I guess the book goes through
an example of building a low-end compiler. And it's on its way here,
woo-hoo.

"The Design and evolution of C++"? I'm afraid it doesn't say a lot
about compiler construction, beyond the choice of parsing technique.
A good book though; fun to read even if you're not interested in C++.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top