开发者

How to create a .Net programming language? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
开发者_开发百科

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 3 years ago.

Improve this question

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?


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, CCI Code Model and AST, that might be useful as well, depends how far along you got.


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.


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.


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.


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.


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


or is there a higher level of abstraction?

Just to be complete, you could output C# or VB.NET. Both compilers are part of the runtime.

Disputable if that would be a 'real' compiler though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜