Making a C++ compiler in Visual C++

I need help with a C++ compiler.

Page 1 of 1

6 Replies - 2521 Views - Last Post: 21 July 2010 - 11:23 AM Rate Topic: -----

#1 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 290
  • Joined: 29-December 09

Making a C++ compiler in Visual C++

Posted 21 July 2010 - 07:17 AM

Ok, I want to make my own C++ compiler, and I thought I could do this myself, but when I noticed there was no namespace for the C++ compiler, I tried looking online, but only found a non-working one:

using namespace Microsoft::

Could anyone be of assistants? Thank you.

Edit: I was thinking it would be this:
System::CodeDom::Compiler::CodeCompiler::FromFile(the file to compile, the name of the file that will be the exe.


This post has been edited by CreaturGames: 21 July 2010 - 07:32 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Making a C++ compiler in Visual C++

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Making a C++ compiler in Visual C++

Posted 21 July 2010 - 07:41 AM

...so you are not trying to make your own compiler but to call a C++ compiler from within your program?

cl.dll is actually the MSVC++ compiler (well part of it anyway there are a couple of compiler dlls used with VS). I don't think MS really made an API for these but you might ask either over on the VisualStudio Blog or though one of the microsoft support newsgroups.

generally though you could just use the cl.exe command line compiler to do whatever compiling you needed to do...
Was This Post Helpful? 0
  • +
  • -

#3 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 290
  • Joined: 29-December 09

Re: Making a C++ compiler in Visual C++

Posted 21 July 2010 - 08:17 AM

Well, I prefer to make my own C++ compiler...
Was This Post Helpful? 0
  • +
  • -

#4 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Making a C++ compiler in Visual C++

Posted 21 July 2010 - 08:35 AM

If so, why are you asking about what Microsoft provides?

EDIT: Or, rather, I should say that your initial post isn't consistent with your desire to make your own compiler.

This post has been edited by Oler1s: 21 July 2010 - 08:36 AM

Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Making a C++ compiler in Visual C++

Posted 21 July 2010 - 09:07 AM

Well you can certainly make your own compiler. A C++ compiler is a bit complicated but definitely doable.

However, I would really suggest working your way up to a C++ compiler. Though if you really want to jump right in I suggest looking at the source for on of the many open source projects based upon the GNU toolset.

To write a compiler you will need to learn about Finite State Machines, Parsers, Lexers, Scanners, Translators -- all of which are very well documented.

You can find many resources here: compilers.net
it has a nice list of free books on compilers here

A great deal of information a the GNU C++ compiler (g++) can be found here: G++ internals

LEX/YACC/BISON -- you will probably need LEX/YACC/Bison or another Parser generator.

You can find the description for the C++ Grammar and Specifications in the C++ standard

comp.compilers newsgroup might also be a resource to look over.

You will also need to know EBNF (Extended Backus-Naur Form) as this is used most often to describe the C++ language.

You should really start small and work your way up. It is not very hard to build your own little scripting language (we even have a tutorial on it by Martyn.Rae). Once you have a little experience with parsing and translation you can move on to bigger and projects like a C++ compiler.

BTW -- just to be sure -- are you talking about writing a compiler or an IDE? people often mix these two things up and there is a HUGE difference.
Was This Post Helpful? 1
  • +
  • -

#6 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1707
  • View blog
  • Posts: 3,275
  • Joined: 30-May 10

Re: Making a C++ compiler in Visual C++

Posted 21 July 2010 - 10:39 AM

Judging from the throw-away last line of the OP, it seems more likely they want to write an IDE, not a compiler.

In other words, some simple "wrapper" to invoke the compiler, and collect the result somewhere.

A very crude hack would be to do something like
std::string commandline = "cl" + " /Fe" + targetname + " " + sourcename;
system( commandline.c_str() );

http://msdn.microsof...y/9s7c9wdw.aspx

Using createProcess() would affort more control over what is happening, but the idea is basically the same.
Was This Post Helpful? 0
  • +
  • -

#7 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 290
  • Joined: 29-December 09

Re: Making a C++ compiler in Visual C++

Posted 21 July 2010 - 11:23 AM

This is not quite what I was looking for, but I could use it.

Thanks anyway. :smile2:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1