2

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.

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

2 Comments

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.
It's worth pointing out that a complete translator is a compiler. All gcc does is translate from C to machine code.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.