Joan Venge
Joan Venge

Reputation: 331250

When C# compiler is written in C#, will one be able to modify it?

I am wondering about it in terms of whether one can implement some new functionality for convenience.

Will this be possible, when it's out?

C# 5.0: compiler as a service:

http://www.matthewlefevre.com/blog/entry.php/c-40-and-c-50/368

Upvotes: 7

Views: 3071

Answers (5)

Richard Anthony Hein
Richard Anthony Hein

Reputation: 10650

Anders Hejlsberg said:

It is one of the directions we are looking at for future versions of C#. Indeed, I see meta-programming as a piece of our bigger “Compiler as a Service” theme that we are working on for a future release. We want to open up our compiler so it becomes an API you can call to compile a piece of code and get back expression trees and/or IL. This enables a whole host of scenarios, such as application programmability, an interactive prompt, user-written refactorings, and domain specific languages that have little islands of C# imbedded in them.
Source

He also said elsewhere (in a Channel9 interview) that they were porting the core of the C# compiler to managed code, to enable this.

There is a demo of this available from the last PDC. The C# compiler is indeed managed code.

Upvotes: 11

JaredPar
JaredPar

Reputation: 755141

That really depends on a lot of different things. Including but not limited too ...

  1. Will Microsoft write a C# compiler in C# ?
  2. Is the compiler delivered in source and binary form or just binary?
  3. Do you want to write a binary extension or just modify the source?
  4. What license will the source and binary be listed under?
  5. Do you want to use the binary in a commercial or hobby project?

Now as to what the answers to these questions are, I have no idea. Nor do I believe there is a stated answer one way or the other to the fundamental question #1. So the overall answer is a big "Don't know"

Upvotes: 5

Avish
Avish

Reputation: 4626

If I understand your question correctly, then I think the answer is a partial yes: building a C# compiler in C# (or actually, in .NET) would make it very easy to expose hooks in the compilation process which users would be able to use from within the language itself.

As an example of a .NET language with a .NET compiler, check out Boo. Since Boo's compiler is written in .NET (mostly in C# and a little Boo, to be precise) it is very easy to hook into the compilation process with things like compilation macros and meta-programming.

I imagine that when the C# compiler is itself written in C#, meta-programming C# would become a lot easier and pretty inevitable. However I doubt Microsoft would make the entire compiler "user-modifiable", since, as stated in other answers, that would mean a support nightmare. Other open source C# compilers exist, however, and might be more liberal in their approach.

Upvotes: 3

RBarryYoung
RBarryYoung

Reputation: 56745

Seriously. NO. This would be a support nightmare for Microsoft. "Bootstrapping" compilers, that is, compilers that compiler the language they are written in have been around (and common) since at least the 70's. That doesn't have anything to do with letting customer change the source cod though, supportability is the entire issue there. So for now, VS-IDE add-ins are about as close as you'll get.

Upvotes: 3

Samuel Carrijo
Samuel Carrijo

Reputation: 17939

Yes, the C# version of the compiler would be the "official Microsoft C#", and you could create your "own C# language" with it. Then you could create a compiler written in your "own C# language" to compile itself or other programs

Upvotes: 2

Related Questions