This probably been asked for but I can\'t google \"How to make a compiler in C++
ID: 654673 • Letter: T
Question
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
Explanation / Answer
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:
Microsoft PE and COFF Specification
An In-Depth Look at the PE File Format
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.