views:

363

answers:

6

I have created a few different full programming languages using some of the various parsing tools available. However, how would someone create a programming language that runs the .Net framework? Would I have to output the .Net IL and compile that or is there a higher level of abstraction?

Also, is there an easy way to get the language working in Visual Studio?

+3  A: 

Your compiler is responsible for converting the code it gets to ILCode. ILCode is the common language any and all .net languages compile to. This code gets interpreted by the JIT-Compiler at runtime. Of course, it can rely on the CodeDom classes in the framework to accomplish that, if you write the compiler in C# for example.

Femaref
Check out this article from MSDN magazine on implementing a compiler in C# for a given language: http://msdn.microsoft.com/en-us/magazine/cc136756.aspx
Justin Niessner
+2  A: 

Your compiler could output either CIL assembly language, or an assembly (.dll / .exe) file.

Take a look at the CLI (Common Language Infrastructure) standard, which describes the CLI (the target platform), the CIL (assembly language), and the binary file format of assemblies.

By the way, the standard is also available as a book with annotations.

stakx
+7  A: 

There is a LOLCode compiler built in C# that might be a good starting point.

http://code.google.com/p/lolcode-dot-net/

As for implementing in Visual Studio, there is an open source view engine called Spark (http://www.sparkviewengine.com/) that did some work with getting intellisense to work. The context is different, but the lesson is the same, it's hard, and it's not a very well documented process.

NerdFury
Spark sounds lots of fun. :)
Patrick
+6  A: 

You'll want to take a look at the Microsoft Research Common Compiler Infrastructure (CCI) project. It provides everything you need to generate the metadata and the MSIL for an assembly. And the debugging .pdb file, rather important to get your language going.

There's a sister project that might be useful as well, depends how far along you got.

Hans Passant
+1  A: 

A great example for integrating your own language into Visual Studio is the Lua Language Support project.

Mike Schenk
A: 

Not sure if this is what you're looking for, but after I had a Question on SO i've created a .net Compiler for Brainf**k as an excersize (Part 6 contains the actual Compiler Source Code and is also on GitHub)

Essentially, the actual Compiler can be written in any .net Language and use the System.Reflection.Emit namespace to create assemblies, classes, methods etc. and emit IL into them.

The actual work of creating a new language obviously involves writing a parser/lexer/analyzer/whatever that can dissect your program into classes and "feed" your compiler - sorry, I have no experience in that, but check this list of resources on how to write a compiler.

You do want to read ECMA-335 to learn how the CLI works: What datatypes it supports and what commands it actually does.

Michael Stum