为什么 DSL 需要解析工具?
难道 DSL 不能像 API 一样简单,因此不需要解析器吗? 或者我误解了领域特定语言的真正含义? 我认为它指的是解决特定领域问题的任何有组织的规则集。 API 似乎符合这个定义,对吧?
Couldn't a DSL be as simple as an API and therefore not need a parser? Or am I misunderstanding what a domain specific language really is? I thought it referred to any organized set of rules for solving a particular domain problem. An API would seem to fit that definition, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以将 DSL 嵌入更通用的编程语言中。 这通常是一个很好的解决方案。 (您可以说这个 DSL 采用特定 API 的形式。)
您还可以创建一种单独的语言,带有自己的解释器,来表示您的领域的概念。 这往往是一项更大的任务,而且通常没有必要。
You can embed a DSL within a more general programming language. This is often a good solution. (You could say that this DSL takes the form of a particular API.)
You can also create a separate language, with its own interpreter, to represent the concepts of your domain. This tends to be a larger undertaking, and is often not necessary.
您将概念与实现混淆了。 特定于领域的语言是被认为“接近”问题领域的想法的任何表示,而不是用于描述一般解决问题的通用语言。
是的,DSL 可以作为 API 实现,它提供了引用问题域中特定概念的函数,但 DSL 在表示为文本文件时同样有效。
实用程序员:从熟练工到大师包含对 DSL 及其有用环境的详细描述,并附有示例。 强烈推荐。
You're confusing the concept with the implementation. A domain-specific language is any representation of an idea that is considered "close" to the problem domain, rather than being a general language for the description of solving problems in general.
Yes, a DSL might be implemented as an API, which provided functions that referred to particular concepts in the problem domain, but a DSL is equally valid when represented as a text file.
The Pragmatic Programmer: From Journeyman to Master contains a good description of DSLs and the circumstances in which they're useful, with examples. Highly recommended.
您仍然只有宿主语言的语义。
例如:命令式语言中的函数式编程不起作用。 所以你在这种命令式语言中添加了一个功能性 DSL...
You would still have only the semantics of the host-language.
E.g.: functional programming in an imperative language does not work. So you have a functional DSL added to this imperative language ...
是的,绝对如此 - 如果宿主语言有足够的灵活性来支持,仅仅 API 就可以很好地用作 DSL。
Ruby 是一种非常适合这种情况的语言,特别是考虑到可选的括号和其他灵活性。
Rails 通常被称为 DSL
用于编写数据库驱动的网络
应用程序。
Rake 是一个带有 DSL 的构建系统
编写(更智能的)makefile。
我自己的 OOFILE 是一个框架,您可以将其视为用 C++ 编写数据库应用程序的 DSL - 它受到 dBase 的启发,大量使用 C++ 运算符重载、本地对象和流习惯用法。
Forth 是一种经典的语言,它模糊了 DSL 和 API 之间的界限,因为 Forth 程序仅由一系列空格分隔的单词组成。 Forth DSL 最令人印象深刻的例子可能是 Abundance - Abundance 是 Forth-基于商业编程语言,用 BBL Forth 编写。 BBL 是一个 32 位 DOS FORTH 编译器。 按原样分发。 请参阅警告。 这不适合胆小的人。 它主要对那些为第三世界开发软件的人感兴趣,在第三世界,你需要在旧的 klunker XT 和 AT 计算机上快速执行。 您可以用它编写一些非常复杂的数据输入程序,这些程序将围绕现代数据输入程序运行。
Yes, absolutely - a mere API will do nicely as a DSL if the host language has sufficient flexiblity to support it.
Ruby is a very good language for such, particularly given the optional parens and other flexibilities.
Rails is often referred to as a DSL
for writing database-driven web
applications.
Rake is a build system with a DSL for
writing (smarter) makefiles.
My own OOFILE is a framework you can regard as a DSL for writing database applications in C++ - it was inspired by dBase and makes very heavy use of C++ operator overloading, local objects and stream idioms.
Forth is classically a language which blurs the line between DSL and API as a Forth program consists of little more than a series of space-separated words. Probably the most impressive example of a Forth DSL is Abundance - Abundance is a Forth-based business programming language, written in BBL Forth. BBL is a 32 bit DOS FORTH compiler. Distributed as is. See the warnings. This is not for the faint hearted. It would be of interest mainly to someone developing software for the third world where you need fast execution on old klunker XT and AT computers. You can write some very sophisticated data entry programs with it that will run circles around modern data entry programs.
当然,图形 DSL 根本不需要解析。
And of course, a graphical DSL would require no parsing at all.