如何创建.Net编程语言?

时间:2020-12-29 10:03:50

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?

我使用了一些可用的解析工具创建了一些不同的完整编程语言。但是,有人会如何创建运行.Net框架的编程语言?我是否必须输出.Net IL并编译它或是否有更高级别的抽象?

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

此外,是否有一种简单的方法可以在Visual Studio中使用该语言?

7 个解决方案

#1


13  

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.

您将需要查看Microsoft Research Common Compiler Infrastructure(CCI)项目。它提供了生成元数据所需的一切,以及程序集的MSIL。调试.pdb文件对于让你的语言变得非常重要。

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

有一个姐妹项目,CCI代码模型和AST,也可能有用,取决于你有多远。

#2


10  

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

有一个用C#构建的LOLCode编译器可能是一个很好的起点。

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

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.

至于在Visual Studio中的实现,有一个名为Spark(http://www.sparkviewengine.com/)的开源视图引擎,它可以帮助智能感知工作。背景是不同的,但是教训是相同的,它很难,而且它不是一个记录良好的过程。

#3


6  

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.

您的编译器负责将其获取的代码转换为ILCode。 ILCode是所有.net语言编译的通用语言。此代码在运行时由JIT-Compiler解释。当然,如果你用C#编写编译器,它可以依赖框架中的CodeDom类来实现它。

#4


5  

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)

不确定这是否是您正在寻找的,但在我有一个问题之后,我已经为Brainf **创建了一个.net编译器作为excersize(第6部分包含实际的编译器源代码,也在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.

本质上,实际的编译器可以用任何.net语言编写,并使用System.Reflection.Emit命名空间来创建程序集,类,方法等,并将IL发送到它们中。

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.

您确实希望阅读ECMA-335以了解CLI的工作原理:它支持哪些数据类型以及它实际执行的命令。

#5


4  

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

您的编译器可以输出CIL汇编语言或汇编(.dll / .exe)文件。

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.

查看CLI(公共语言基础结构)标准,该标准描述了CLI(目标平台),CIL(汇编语言)和程序集的二进制文件格式。

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

顺便说一句,该标准也可作为带注释的书籍使用。

#6


2  

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

将自己的语言集成到Visual Studio中的一个很好的例子是Lua语言支持项目。

#7


1  

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.

要完成,您可以输出C#或VB.NET。两个编译器都是运行时的一部分。

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

如果那将是一个“真正的”编译器,那将是有争议的。

#1


13  

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.

您将需要查看Microsoft Research Common Compiler Infrastructure(CCI)项目。它提供了生成元数据所需的一切,以及程序集的MSIL。调试.pdb文件对于让你的语言变得非常重要。

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

有一个姐妹项目,CCI代码模型和AST,也可能有用,取决于你有多远。

#2


10  

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

有一个用C#构建的LOLCode编译器可能是一个很好的起点。

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

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.

至于在Visual Studio中的实现,有一个名为Spark(http://www.sparkviewengine.com/)的开源视图引擎,它可以帮助智能感知工作。背景是不同的,但是教训是相同的,它很难,而且它不是一个记录良好的过程。

#3


6  

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.

您的编译器负责将其获取的代码转换为ILCode。 ILCode是所有.net语言编译的通用语言。此代码在运行时由JIT-Compiler解释。当然,如果你用C#编写编译器,它可以依赖框架中的CodeDom类来实现它。

#4


5  

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)

不确定这是否是您正在寻找的,但在我有一个问题之后,我已经为Brainf **创建了一个.net编译器作为excersize(第6部分包含实际的编译器源代码,也在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.

本质上,实际的编译器可以用任何.net语言编写,并使用System.Reflection.Emit命名空间来创建程序集,类,方法等,并将IL发送到它们中。

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.

您确实希望阅读ECMA-335以了解CLI的工作原理:它支持哪些数据类型以及它实际执行的命令。

#5


4  

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

您的编译器可以输出CIL汇编语言或汇编(.dll / .exe)文件。

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.

查看CLI(公共语言基础结构)标准,该标准描述了CLI(目标平台),CIL(汇编语言)和程序集的二进制文件格式。

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

顺便说一句,该标准也可作为带注释的书籍使用。

#6


2  

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

将自己的语言集成到Visual Studio中的一个很好的例子是Lua语言支持项目。

#7


1  

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.

要完成,您可以输出C#或VB.NET。两个编译器都是运行时的一部分。

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

如果那将是一个“真正的”编译器,那将是有争议的。