使用 Microsoft Visual Studio 进行文本领域特定语言 (DSL) 开发
我做了一些关于在 Visual Studio 中开发 DSL 的搜索。一开始,我发现VS2010有一个可视化和建模SDK。它有一个叫做 DSL 工具的工具。但似乎仅适用于图形DSL开发。
然后我看到一些帖子说“Oslo”是一个用于开发文本DSL的工具,它“是”微软的产品——微软不再支持该工具。 http://blogs.msdn.com/b/modelcitizen/archive/2010/09/22/update-on-sql-server-modeling-ctp -repository-modeling-services-quot-quadrant-quot-and-quot-m-quot.aspx
因此,我想知道如果我想开发文本DSL,什么工具是最好的?如果我使用带有 FSLex 和 FSYacc 的 F# powerpack 实现 DSL 解析器,您有何看法?
I did some searches on developing a DSL in visual studio. At the beginning, I found out there is a Visualization and Modeling SDK for VS2010. It has a tool called DSL tool. But it seems that it is only for graphical DSL development.
Then I saw some posts saying "Oslo" is a tool for developing textual DSL, which "was" a Microsoft product - Microsoft no longer supports the tool. http://blogs.msdn.com/b/modelcitizen/archive/2010/09/22/update-on-sql-server-modeling-ctp-repository-modeling-services-quot-quadrant-quot-and-quot-m-quot.aspx
Therefore, I would like to know if I want to develop a textual DSL, what tool is the best? What do you think if I implement a DSL parser making use of F# powerpack with FSLex and FSYacc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我目前正在使用 FsLex/FsYacc 开发几个基于外部文本的 DSL。我使用的是手动解析器,但我发现 FsLex/FsYacc 在设计阶段更容易维护。
FsLex/FsYacc 不像 ANTLR 那样复杂,但由于大多数 DSL 都相当简单,因此 FsLex/FsYacc 是在 Visual Studio 中使用的完美选择。保持 DSL 简单是一件好事,因为它们旨在受到限制并且易于学习。
我发现 Martin Fowler 的书是一个很好的资源,与其说是示例和细节,不如说是 DSL 思想的百科全书。他对 DSL 的可用性和其他设计方面的讨论也值得一读。正如 Toumas 所指出的,它不涵盖 F# 或函数式语言。福勒先生写道,他缺乏这些主题的经验,无法及时将这本书推向市场。
在赞扬了 FsLex/FsYacc 之后,我仍然希望有人能为 F# 编写一个好的 ANTLR 后端。 :)
-尼尔
I am currently developing several external text-based DSLs using FsLex/FsYacc. I was using a hand parser, but I find the FsLex/FsYacc much easier to maintain in the design stage.
FsLex/FsYacc are not as sophisticated as ANTLR, but since most DSLs are fairly simple, FsLex/FsYacc are a perfectly sound choice for use within Visual Studio. And keeping DSLs simple is a good thing, since they are intended to be restricted and simple to learn.
I find Martin Fowler's book to be a good resource, less for the examples and details than as an encyclopedia of DSL ideas. His discussion of useability and other design aspects of DSLs is also worth reading. As Toumas indicated, it does not cover either F# or functional languages. Mr. Fowler writes that he lacked the experience in those subjects to bring the book to market in a timely way.
Having praised FsLex/FsYacc, I do still wish someone would write a good ANTLR back-end for F#. :)
-Neil
我是嵌入式 DSL 的粉丝,就像
http://lorgonblog.wordpress.com/2010/04/15/using-vs2010-to-edit-f-source-code-and-a-little-logo-edsl/
http://lorgonblog.wordpress.com/2010/04/ 16/fun-with-turtle-graphics-in-f/
,您只需使用 F# 语法和一些好的函数名称以及可能的其他语法技巧(列表、工作流程等)即可获得“看起来像就像也许它是另一种语言”,但实际上只是 F#。
但是,是的,对于外部 DSL,您只需要一个语法/解析器/等工具链,FsLex/FsYacc,或者 ANTLR 或 FParsec 都是不同的选择。 (我对这些都没有足够的经验,无法了解它们之间的权衡。)
I am a fan of embedded DSLs, a la
http://lorgonblog.wordpress.com/2010/04/15/using-vs2010-to-edit-f-source-code-and-a-little-logo-edsl/
http://lorgonblog.wordpress.com/2010/04/16/fun-with-turtle-graphics-in-f/
where you just use leverage F# syntax with some good function names and possibly other syntax cleverness (lists, workflows, ...) to get code that "looks like maybe it is another language" but is actually just F#.
But yes, for external DSLs, you just need a grammar/parser/etc tool chain, and either FsLex/FsYacc, or maybe ANTLR or FParsec are various choices. (I don't have enough experience with any of these to know trade-offs among them.)
自从发表之前的文章以来,我还购买并阅读了 Terence Parr 的《语言实现模式》一书的部分内容。它非常出色,尽管比马丁·福勒的书技术性更强(加上一些额外的材料,它可能是新千年的“龙之书”)。这些示例强烈基于 Java 和 ANTLR,但文本才是主要内容,因此无论一个人的语言开发环境如何,这本书都是有用的。
有趣的是,两本书之间几乎没有重叠。 Martin Fowler 的书很好地涵盖了基本 DSL 的设计和实现,例如用于规范和配置的那些,而 Terence Parr 的书则更具技术性,涵盖了通过更复杂的语言和字节码一直延伸的领域机器。如果您有预算的话,我推荐两者,否则,在其给定领域内,两者都是一个很好的选择。
Since having made my earlier post, I have also bought and read parts of Terence Parr’s book “Language Implementation Patterns.” It is excellent, though quite a bit more technical than Martin Fowler’s book (with some additional material it could be a “Dragon Book” for the new millennium). The examples are strongly based in Java and ANTLR, but the text is the main thing, so the book is useful regardless of one’s language development environment.
Interestingly, there is little overlap between the two books. Martin Fowler’s book does a good job of covering the design and implementation of basic DSLs, such as those used for specification and configuration, while Terence Parr’s book is more technical and covers the realm extending all the way up through more sophisticated languages and byte-code machines. I recommend both if you can budget for them, otherwise, either is an excellent choice within its given domain.
Martin Fowler 有一本关于 DSL:s 的新书。遗憾的是,它不会过多讨论 Microsoft 的工具或函数式语言。
微软不再支持图形工具“Quadrant”,但MGrammar仍然支持并集成到SQL Server中,对吧? MGrammar 是“DSL 制作语言”。
尽管如此,我还是想说函数式语言(阅读:F#)是正确的选择。
本书有一个如何使用 F# 制作 DSL 的简单示例:http://www.manning.com/佩特里切克/
谷歌还发现了许多关于这个主题的其他很好的参考资料。
Martin Fowler has a new book about DSL:s. Sadly, it won't discuss much about Microsoft's tooling nor functional languages.
Microsoft no longer support the graphical tool "Quadrant", but MGrammar is still supported and integrated to SQL server, right? MGrammar is the "DSL making language".
Still, I would say that functional languages (read: F#) are the way to go.
This book has a simple example of how to make a DSL with F#: http://www.manning.com/petricek/
and also Google finds many other good references about this topic.
尝试 MBase,但只有当您的 DSL 足够复杂以至于需要高效的编译器时才值得使用和 PEG 语法。否则 FsYacc 就足够了。
Try MBase, but it only worth using if your DSL is complicated enough to require an efficient compiler and a PEG grammar. Otherwise FsYacc is more than enough.
我们的 DMS 软件重组工具包旨在处理任意 DSL(我恰好是架构师)。
大多数人认为,如果你有一个解析器,你就已经足够了,这在技术上是正确的,就像如果你有晶体管,你就可以建造一台计算机一样。
根据我的经验,您需要的不仅仅是一个解析器:您需要构建符号表的方法,以便您的生成器知道特定标识符的含义是什么,分析规范的方法,轻松编码翻译和应用优化的方法生成结果。
DMS 提供所有这些功能来支持构建 DSL。从这个意义上说,它远远超出了 F#。
Our DMS Software Reengineering Toolkit is designed to handle arbitrary DSLs (I happen to be the architect).
Most people think if you have a parser you have enough, and it is technically true, in the same sense that if you have transistors you can build a computer.
In my experience you want a lot more than just a parser: you need ways to build symbol tables so that your generator knows what the meaning of a particular identifier is, means to analyze the specification, ways to easily encode your translation and to apply optimizations to generated results.
DMS provides all these capabilities to support building DSLs. And in that sense, it goes much beyond F#.