什么是“特定领域语言”?

发布于 2024-12-11 03:07:32 字数 456 浏览 3 评论 0原文

可能的重复:
什么是 DSL,我应该在哪里使用它?< /a>

我听说过这个术语用了很多...对于一种语言来说,“特定于领域”到底意味着什么?

另外,对于语言(例如 Groovy支持域意味着什么-特定语言?

Possible Duplicate:
What is a DSL and where should I use it?

I've heard the term used a lot... what exactly does it mean for a language to be "domain-specific"?

Also, what does it mean for a language (e.g. Groovy) to support domain-specific languages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃酥萝莉 2024-12-18 03:07:32

“领域特定语言”是一种可以简洁地表达一类问题(或问题的解决方案)的语言,通常是因为词汇表与问题领域的词汇表一致,并且符号与所使用的符号相似(如果可能)由该领域的专家撰写。

这真正的意思是表示你可以说的内容的语法,以及定义这些内容的含义的一组语义。这使得 DSL 在实现方式方面与其他传统编程语言(例如 Java)一样。事实上,您可以将此类传统语言视为“DSL”,它们擅长描述问题的过程解决方案(但不一定擅长描述它们)。这意味着您需要与处理传统语言相同的一套机器来处理 DSL,而这本质上就是编译器机器。

Groovy 有一些这样的机制(根据设计),这就是它可以“支持”DSL 的原因。

请参阅域特定语言,了解有关 DSL 的一般讨论以及特定类型的 DSL。元编程机制对于实现它们非常有帮助。

A "domain specific language" is one in which a class of problems (or solutions to problems) can be expressed succinctly, usually because the vocabulary aligns with the that of the problem domain, and the notation is similar (where possible) to that used by experts that work in the domain.

What this really means is a grammar representing what you can say, and a set of semantics that defines what those said things mean. This makes DSLs just like other conventional programming langauges (e.g., Java) in terms of how they are implemented. And in fact, you can think of such conventional languages as being "DSL"s that are good at describing procedural solutions to problems (but not necessary good at describing them). The implications are that you need the same set of machinery to process DSLs as you do to process conventional languages, and that's essentially compiler machinery.

Groovy has some of this machinery (by design) which is why it can "support" DSLs.

See Domain Specific Languages for a discussion about DSLs in general, and a particular kind of metaprogramming machinery that is very helpful for implementing them.

甜味拾荒者 2024-12-18 03:07:32

对于你的第一个问题,用谷歌搜索一下就足够了。

至于第二个问题:你可以用任何语言实现 DSL。您甚至可以用几乎任何语言实现 eDSL。但有些语言在这方面比其他语言要好得多。关键功能是元编程 - 能够以您的主机语言生成代码,这意味着您可以在任何地方插入 eDSL 编译器。促进编译器构建的功能也很有用 - 例如,开箱即用的解析工具、可扩展或只是灵活的宿主语言语法、用于表示 AST 的代数数据类型、用于简化编译器转换的模式匹配等。有一系列的可能性,一方面是完全静态且不可扩展的语言,另一方面是绝对灵活的语言。

For your first question a bit of googling will be sufficient.

As for the second question: you can implement DSLs in any language. You can even implement eDSLs in almost any language. But some languages are much better in that than the others. The key feature is metaprogramming - an ability to generate code in your host language, which means you can plug in a compiler of your eDSL anywhere. Features which facilitate compiler construction are also useful - e.g., out of box parsing tools, extensible or just flexible syntax of the host language, algebraic data types for representing ASTs, pattern matching for simplifying compiler transformations, etc. There is a continuum of possibilities, with entirely static and unextensible languages on one side and absolutely flexible languages at the other side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文