I want to write my own programming language as an extension of the c programming language. The entire programming language that I am inventing are simply shorthands which translate to valid c code. For example:

namespace TcpConnection {
void* connect(char *addr)
}

would translate to:

void* TcpConnection_connect(char *addr)

All that is done is a simple name replacement. This is only one example of an extension which I want to provide. Another simple extension would be function overloading (this would concatenate to the end of the function name the types of its arguments.

In any case, the result is perfectly valid C code. Is there any way to do this without going into gcc code?

4 Answers
4

You could write a preprocessor that parses your language and compiles it to C, which is then passed on to gcc. This is how early implementations of C++ worked. However, you may prefer to hack on LLVM's clang, which is designed to support several C-family languages and, as part of LLVM, is also designed to be more modular and easier to extend.

For prototyping, maybe just go with a preprocessor written in the language of your choice (C, Perl, Python...) and then build it into your Makefile rules. Just to get an easy, low-cost way to try it all out...