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
I think you're asking the wrong question:
How you make I compiler in C++?
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 (
.exe) file on the Windows platform?
Look into the specs of the PE format. More details available here:
How to write a compiler for C++ in C++?
That is, of course, assuming that you want to compile c++ files, but I'm just guessing here as you don't clearly state what you want to compile...
And from the way you formulate your answer, you already know how to do that, though you raise points about the OO model.
Please clarify your question if you need more.
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.