Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First off, I know this is a question asked by MANY other programmers before me. But I couldn't find any useable resource that could help me.

Well, I'm creating an programming language called "Light" the syntax is comparable to python but it has an strict object-orientated concept.

I have made an interpreter ( in C++ ) for this language yet, my problem is how to turn this into an executeable. ( Or simply: how do I make an compiler ? )

Thanks for your attention

P.S.: I've found some links to a very old tutorial but it is in Pascal...

EDIT: Well, well. Now I have found a suitable tutorial for C++. About the project: There have been some changes. Now the language is called "Q." ( kju Dot ).

share|improve this question
first learn the target language, then see how you would translate the basic code blocks from your language into the the other language – ratchet freak Feb 23 '13 at 20:02
Are you "merely" trying to write a compiler (with the background knowledge from previously implementing an interpreter for the same language), or are you literally trying to turn your interpreter into a compiler? Your phrasing is giving me ideas ;-) – delnan Feb 23 '13 at 20:02
A Futamura projection? – Dan D. Feb 24 '13 at 5:02
That's trivial - just specialise your interpreter against a particular source code to get its compiled version. – SK-logic Feb 24 '13 at 12:31
up vote 11 down vote accepted

The first couple of steps lexing/parsing (and analysis, depending on how that's structured) can be the same. But you will need to convert your representation to a code-generating representation. Typically LLVM is used for hobbyists as it is pretty much the only remotely decent free code-generating library around.

share|improve this answer
This is exactly what I was going to write, but you got to it first. Have a +1. – Mason Wheeler Feb 23 '13 at 20:20
Wrong. Simply emiting C (or C++, or whatever else) is much more popular for the hobbyist compiler projects. LLVM is much more complicated. And JVM or .NET are not any worse than LLVM for this purpose. – SK-logic Feb 24 '13 at 12:33
Those compilers do not produce executables, which the OP does want. As for .NET/JVM, it really depends on the semantics of his language. – DeadMG Feb 24 '13 at 14:29
@DeadMG, ghc, for example, is perfectly capable of producing executables via C. As well as hundreds of the other C-based compilers. Does your religion forbid you to use popen(...) in a compiler? Then you have to throw away gcc itself. As for .NET, unlike JVM it's capable of catering for quite a wide variety of semantics, due to its unsafe features. – SK-logic Feb 25 '13 at 8:55
I used LLVM (with python bindings) and it worked like a charm. :) – Julien Apr 25 '15 at 17:05

If all you really want is an executable, you can append the script to the end of an interpreter executable and have it run that.


Alternately, you can just have the interpreter load the code from a file in the same directory as the interpreter and get largely the same result, just with multiple files.

A true compiler would convert the code into some other language and use the compiler for that language. But if you just want to distribute executables, there's no need to do that.

share|improve this answer
Well, I know this way of packing :) used it for Python ( before I heard of py2exe ). For me this is cheating and the other problem is performance. My language how it is now is low level BUT strict objectorientated. – Julien Feb 23 '13 at 22:17

You may also want to consider using System.Reflection.Emit from the .NET runtime to generate a .NET executable. This will give you access to an existing object-oriented environment which has already solved some problems for you, and the resulting exe can be platform-independent. The runtime will compile the intermediate code in the .exe to machine code as needed, so performance should be comparable to what you'd get from compiling directly to native code.

share|improve this answer
Probably a nice idea, but I designed my language to be low-level at some point ;) Now I am trying to dig through Intels Documentation of OpCodes. – Julien Nov 11 '14 at 18:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.