Click here to Skip to main content
15,887,440 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do Compilers write exe files? I cannot understand machine language. Is there any way to do something like that? I want to create a compiler. If anyone knows how, inform me. Please!
Posted
Updated 28-Aug-12 2:26am
v2
Comments
[no name] 27-Aug-12 9:33am    
There is absolutely no possbile way that someone could tell you how to write a compiler in a forum post. You have a lot of research ahead of you.
Philip Stuyck 27-Aug-12 9:53am    
You'll be in for a very long ride and will probably fail to do it. It is not something that you would do just like that. Many people work on the same compiler. It requires a lot of skills and knowledge, also in assembly language and OS specifics.
Legor 28-Aug-12 4:45am    
Why not just take one of the dozens tested C++ Compilers? It's not like one can do something like that over night.

My favourite book on the subject is: Compiler Design in C[^], and I would also recommend The Definitive Antlr Reference: Building Domain-Specific Languages[^]

You should also have a look at NASM[^]

This a full c++ compiler: clang[^]

Best regards
Espen Harlinn
 
Share this answer
 
v2
For a simple, practical introduction you may check out the oldie-goldie Crenshaw's Let's build a compiler[^].
If you need theoretical background, a classical is the Dragon book[^].
 
Share this answer
 
You can write your own compiler as a proof of concept using the tools called "compiler compilers" . Although these will not be the best compilers as compared to the advanced compilers today. Check here
http://en.wikipedia.org/wiki/Compiler-compiler[^]

http://accent.compilertools.net/[^]
 
Share this answer
 
v2
An "exe" is a binary file with multiple sections. The first section is ALWAYS a standard header (read Microsoft PE-COFF file format). The next sections (if any) can be sections of code (machine language) or sections of data (images, sounds, strings, video, etc).

A compiler will transform you c++ code in machine language.
A linker will take the machine language generated by the compiler, the images, the strings and will generate an "exe" file: first will write the mandatory PE header, then will write the machine language code and then rest of the data required for a functional "exe". Linkers are invoked automatically by modern compilers(GCC, Borland C++ and Microsoft Visual C++ do this).

Before you can write a C++ compiler you MUST:
- Learn to program in one of this languages: C, C++, Java.
- Read the Dragon Book(Compilers: Principles, Techniques, and Tools - Alfred Aho, Ravi Sethi, Jeffrey Ullman).
- Read Intel x86 ISA
- Read Microsoft PE-COFF file format

Generally, a complete C++ compiler is developed by a team of multiple programmers in 3-5 years. Understanding them will take you about one week. Writing alone a C++ compliant compiler is not possible. This is my personal view and you can prove me wrong.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900