tags:

views:

1455

answers:

5

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

+5  A: 

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"

JaredPar
But for C# 5.0, MS is gonna write it using C#, right?
Joan Venge
Why would they do that?
mquander
To offer C# as a service functionality.
Joan Venge
What on Earth is "C# as a service functionality?"
mquander
The answer to 1 is yes. See my answer for info. The answer to 2 is binary. 3 - don't know. 4 - probably the same as the current license. 5 - don't know. Meta-programming will be possible, but not adding to the C# language and compiler directly.
Richard Hein
@Richard, the key is "future release". Future can be a long or short time. There is no decision on when this may or may not happen.
JaredPar
+2  A: 

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

Samuel Carrijo
And then you could write a compiler to parse the code from your compiler and create a meta compiler ad infinitum until your eyes bleed out of their sockets
Jason Watts
Yes you could do that. There's a nice demo where you can see how easy that would be ... the link is in my answer.
Richard Hein
+3  A: 

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.

RBarryYoung
They are however, porting the core of the C# compiler to managed code and are going to expose the APIs as a service. Straight from Anders Hejlberg. See my answer for the links.
Richard Hein
FYI to whoever downvoted me: this question has been significantly changed from the original question which was "When the C# compiler is written in C# will we be able to edit it?" My answer was to that question, not whatever is has currently been edited into.
RBarryYoung
+3  A: 

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.

Avish
+9  A: 

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.

Richard Hein