This probably been asked for but I can't google "How to make a compiler in C++" because I will just get "How to compile C++" as the results. Anyway, for my question, I'd like to make a simple programming language in C++. Now I understand basic file IO stuff but what I don't get is how to build a EXE. The problem here is I don't know how EXEs exactly are "planned out", granted that most people don't. I was going to simply parse the language into assembly and assemble it using an assembler. But I don't want to do that, I want to actually compile it directly into a EXE. Does anyone know how this would be done? PS: To all you people who say making a compiler is virtually impossible, it's a fairly fast process, it's just implementing OOP features that's hard
closed as too broad by gnat, MadKeithV, Kilian Foth, Dan Pichelman, MichaelT Sep 2 at 15:59
There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.
There is not much difference between understanding assembly and understanding the machine code that it creates. You should create your own assembler or at least study the disassembly of asm that has been assembled by some toolchain, such that you can create your own machine code. Again not a stretch if you are proficient in assembly. The next issue is the EXE file format. Googling should make that quite easy. As far as planning out what goes in the EXE, that is basic programming, not specific to an EXE.
You will most likely be successful if you start by having your language compiler output assembly language, then use an existing toolchain (assembler and linker) to turn that assembly language into an EXE. Create and debug your language and compiler. Then replace the assembler and linker by generating the machine code directly.
I think you're asking the wrong question:
As in with any other language, actually. You'll need to write something that takes an input (likely from files) and compiles this input into something that's machine-readable and follows a specific format (in your case, C++).
So your question isn't correct and relevant. The questions you should be asking are:
What are the specifications for an executable (