如何在VB.NET或c#中编写基于CLR的自己的VS2010语言? [英] How do I write my own VS2010 language based on CLR in VB.NET or c#?

查看:89
本文介绍了如何在VB.NET或c#中编写基于CLR的自己的VS2010语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我想基于c#创建自己的编程语言。

有谁知道我该怎么办?

我在谷歌上搜索过但我什么都没发现......

我想要自己的语言支持:

语法高亮,智能感知,并编译为CLR并支持所有.net功能并在Visual Studio 2010中工作。



提前致谢!

Hi! I want to create my own programming language based on c#.
Does anyone know how can I do it?
I searched on google and I found nothing...
I want my own language to support:
Syntax Highlight, Intellisense and to be compiled to CLR and to support all .net features and to work in Visual Studio 2010.

Thanks in advance!

推荐答案

对于编译器:因为您要创建的语言将基于C# ,创建它的最简单方法可能是将语言编译为C#,并将C#编译成可执行文件。要将C#代码编译为可执行文件,请查看此处:

如何以编程方式编译代码使用C#编译器 [ ^ ] < br $> b $ b

对于Visual Studio支持:您必须编写一个Visual Studio扩展,它将处理语法突出显示等。你可以从这里开始:

构建和发布Visual Studio 2010的扩展 - Visual Studio博客 - 站点主页 - MSDN博客 [ ^ ]

(此博客文章的例子都在VB.NET中,但将它们移植到C#应该不会太难。)



祝你好运!
For the compiler: as the language you want to create would be based on C#, the easiest way to create it might be to compile your language into C#, and compile the C# into an executable. To compile C# code to an executable, take a look here:
How to programmatically compile code using C# compiler[^]

For the Visual Studio support: you'll have to write a Visual Studio extension, which would take care of the syntax highlighting and such. You can start here:
Building and publishing an extension for Visual Studio 2010 - The Visual Studio Blog - Site Home - MSDN Blogs[^]
(Examples in this blog posts are in VB.NET, but it shouldn't be too hard to port them to C#).

Good luck!


有关域特定语言的阅读这里 [ ^ ]。也许它可以帮到你。
There is a read on Domain Specific Langauges here[^]. Maybe it can help you.


不幸的是,解决方案1或2都是偏离主题的。他们没有告诉你如何使用真正的编译器构建自己的语言。您需要从您的语言编译为CIL,而不是其他任何东西。编译到C#,很可能,首先是低效的(额外的编译步骤会占用构建时间)并且不灵活。你真的需要编译成CIL。



如果使用CodeDOM,这并不难。您可以将语言编译为CodeDOM树。具体方法如下:使用CodeDOM [ ^ ]。br />


参见:如何:使用CodeDOM创建类 [ ^ ]。



理想情况下,您应该为自己创建自己的代码语言形式为 CodeDomProvider 。这样,您可以扩展CodeDOM以使用您的语言。请注意,这与将语言编译为CIL不同。请参阅: CodeDomProvider类(System.CodeDom.Compiler) ) [ ^ ]。



有关此问题的更深入分析,请参阅此CodeProject文章:创建CodeDOM:建模代码语义(第2部分) [ ^ ]。



-SA
Unfortunately, both Solution 1 or 2 are off-topic. They don't tell you a word on how build your own language with the "real" compiler. You need to compile from your language to CIL, and nothing else. Compilation to C#, being quite possible, will be, first of all, inefficient (extra compilation step will eat up build time) and inflexible. You really need to compile into CIL.

And this is not too hard to do if you use CodeDOM. You can compile your language into CodeDOM tree. This is how: Using the CodeDOM[^].

See also: How to: Create a Class Using CodeDOM[^].

Ideally, you should create your own code provided for your language in the form of CodeDomProvider. This way, you can extend CodeDOM to use your language. Note that this is not the same as compilation of your language to CIL. Please see: CodeDomProvider Class (System.CodeDom.Compiler)[^].

For deeper analysis of this problem, please see this CodeProject article: Creating a CodeDOM: Modeling the Semantics of Code (Part 2)[^].

—SA


这篇关于如何在VB.NET或c#中编写基于CLR的自己的VS2010语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆