tags:

views:

107

answers:

3

I am currently writing a programming language in C/C++ as an exercise (but mostly for fun). At the moment it compiles into a list of commands that are then executed (kind of like a low-level API). Its working fantastically, however, I think it would be more exciting if instead of having a interpreter executable, having the language actually compile into a .exe file. I don't know if it is possible or how challenging this might be. I could not find any resources to help me with this. - Thanks in advance.

+2  A: 

It would certainly be possible, although it could be a fair bit of work to produce all of the necessary parts to make a runnable binary. If that is what you are trying to learn about, then it could be a great exercise.

However, if you are simply looking to make it run faster, there are other options. For example, you could possibly emit C/C++ code based on the input program and then compile/link that.

Mark Wilkins
Writing a translator that converts the input program to C source is probably a good first step (by the way, that's how the first C++ implementation worked!). Once you've solved that, writing a compiler frontend for your language should be a bit easier.
caf
It's worth pointing out that a complete translator is a compiler. All gcc does is translate from C to machine code.
Daniel
+4  A: 

You could consider writing a frontend for LLVM (tutorial) or GCC (article from linux journal) - if thats still fun for you is a different question.

Georg Fritzsche
+1 for llvm. Beat me to it.
Niall C.
A: 

First, you have to be clear about the syntax and lexical of your language code in a formal way. Then, you could take a look on lex. That builds a lexical analyzer, that you can use to generate the C code (or whatever) you need.

If your language doesn't use dynamic types, then you could get it easy.

KikoV