有没有关于 DSL 设计的书籍/论文? (不是 DSL 实现)

发布于 2024-12-15 00:04:41 字数 1460 浏览 1 评论 0原文

我必须为非程序员(我们公司的客户)创建一个 DSL,它需要提供一些高级语言功能(循环、条件表达式、变量...... - 所以它不仅仅是一个“简单”DSL)。

使用 DSL 应该很容易;人们应该能够尝试它并通过玩耍来学习它。我们希望实现类似于 Microsoft Excel 中的宏的功能 - 许多 Excel 用户可以创建简单的公式、求和或计算,但从未使用过“真正的”(通用)编程语言。

显然,并不是每个 Excel 用户都理解更复杂的内置方法(如 When()),但他们可以使用简单的方法,如 SUM() 或 AVG()。我希望使用 DSL 实现类似的效果 - 用户应该能够直观地使用它并定义简单的规则或执行简单的计算。同时,DSL 应该为更倾向于技术的人提供更高级别的功能 - 例如循环、if 语句、可能的方法或 lambda。

这引出了我的问题:什么语言结构是直观的、易于学习和理解的?

在当前的 DSL 实验版本中,我们尝试了方法链接方法,例如:<代码>list.where(item -> item.value > 5).select(item -> item.name + " " + item.value))。 将 whereselect 视为 foreach 构造,其中 item 是表示循环中当前项目的变量。

我们首先尝试这种方法的原因是它很容易支持代码完成 - 每当用户输入句点 (.) 时,显示可能的方法列表。然而,我不确定这个概念是否符合我的直观且易于理解和阅读的标准。

如果没有大括号,对用户来说是否更容易/更具可读性? (就像在 LINQ 中一样:从列表中的 item.value > 5 选择 item.name + " " + item.value)。然而,在这种情况下,没有“边界” - 在前面的示例中,用户知道语句以最后一个右大括号结束 - 在这种情况下,如果他在 select 部分之后输入更多代码语句,他不知道它是否属于该语句(除了解析器也不知道并且必须有某种闭包的事实)。

我希望通过这两个例子我的问题能更清楚一些 - 我正在寻找设计指南、最佳实践、现实生活经验,可能是语言构建的研究材料对他人有利 - 或者对某些语言结构的利弊进行一些评估。

我不是在寻找有关如何创建 DSL、我可以使用哪些解析器生成器等的信息,而且我也无法使用现有的通用语言(Ruby、Python... )而不是因为 DSL 的使用方式。 (DSL 在解析时直接与我们的对象模型一起工作 - 我不会在这里详细介绍,因为这个问题已经足够长了)。

编辑:也许我应该指出,“语言构造”是指语法,即编写某些内容的方式,而不是语言应提供的功能类型 - 我们已经有了 DSL 的功能列表必须提供。问题是如何最好地表达这些功能以允许创建(和维护)简单和复杂的公式。

I have to create a DSL for non-programmers (customers of our company) that needs to provide some higher-level language features (loops, conditional expressions, variables ... - so it's not just a "simple" DSL).

Working with the DSL should be easy; people should be able to experiment with it and learn it by playing around. We want to achieve something similar to Macros in Microsoft Excel - many Excel users can create simple formulas, sums or calculations and have never worked with a "real" (general purpose) programming language.

Obviously not every Excel-user understands the more complicated built-in methods (like When()), but they can use simple methods like SUM() or AVG(). I want to achieve a similar effect with the DSL - uesrs should be able to intuitively work with it and define simple rules or perform simple calculations. At the same time the DSL should offer higher-level features for the more technically inclined - like loops, if-statements, possibly methods or lambdas.

And this leads me to my question(s): What language constructs are intuitive, easy to learn and understand?

In the current, experimental version of the DSL we tried a method-chaining approach, example: list.where(item -> item.value > 5).select(item -> item.name + " " + item.value)).
Think of where and select as foreach constructs where item is a variable that represents the current item within the loop.

The reason we tried this approach first is that it would be easy to support code completion - whenever a user enters a period (.), show a list of possible methods. However I'm not sure this concept meets my criteria of being intuitive and easy to understand and read.

Is it easier / more readable for users if there are no braces? (like in LINQ: from item in list where item.value > 5 select item.name + " " + item.value). However in this case, there are no "boundaries" - in the prior example the user knows that the statement ends with the last closing brace - in this case, if he types more code after the select part of the statement, he doesn'- know if it belongs to the statement or not (apart from the fact that the parser wouldn't know either and there had to be some sort of closure).

I hope my question is a bit clearer with these 2 examples - I'm looking for design guidelines, best practices, real-life experiences, probably research material of which language constructs are favorable to others - or some evaluation of pros and cons of certain language constructs.

I am not looking for information on how to create a DSL, on what parser generators I could use etc. and I also can't use an existing general-purpose language (Ruby, Python, ...) instead because of the way the DSL is used. (The DSL, when parsed, works directly with our object model - I won't go into details here since this question is already long enough as it is).

Edit: Perhaps I should point out that by "language constructs" I mean the syntax, the way something is written, not what kind of functionality the language should offer - we already have a list of featuers the DSL has to provide. The question is how these features are best expressed to allow the creation (and maintenance) of simple and complex formulas.

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

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

发布评论

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

评论(3

遗心遗梦遗幸福 2024-12-22 00:04:41

虽然我不想回答自己的问题,但我想关闭此问题并为那些寻找类似信息的人留下一些链接。 (我接受这个的原因是,虽然艾拉的回答朝着正确的方向发展,但该报告有点过时了——詹姆斯的回答与我的问题无关)。

因此,关于语言的可用性:

符号的认知维度是评估可用性的一个很好的框架符号或任何与此相关的认知工件。

自然编程网站包含许多有趣的出版物,对我来说最有用的是新手编程系统设计中的可用性问题

最后,最重要的是最近与我的问题相关的活跃研究领域似乎是最终用户开发。搜索该领域的出版物应该会得到很多有用的信息。

While I don't like to answer my own questions, I want to close this one and leave some links for those looking for similar information. (Reason I accept this one is that, while Ira's answer goes in the right direction, the report is kinda outdated – James' answer is unrelated to my question).

So, on to usability of languages:

The Cognitive Dimensions of Notations are a great framework to evaluate the usability of a notation, or any cognitive artifact for that matter.

The Natural Programming site contains lots of interesting publications, the most useful for me was Usability Issues in the Design of Novice Programming Systems

Finally, the most recently active research field related to my question seems to be End User Development. Searching for publications in that area should result in quite a lot of useful information.

浮萍、无处依 2024-12-22 00:04:41

在我看来,设计领域的关键问题是它的概念以及它们之间的关系。这由域分析涵盖,听起来您已经完成了,但无论如何都是一个关键链接:

Guillermo Arango 谈领域分析

通过这样的分析,您想要设计一个领域,包括表达问题和解决方案的方法。维基百科关于域工程
显然是第一名,但我发现它非常不满意,因为它没有引用阿兰戈的作品。

(Arango 是我在 20 世纪 80 年代在 UCI Irvine 的办公室同事,当时领域分析和工程是一个热门话题)。

您似乎想要的是语言设计中的人为因素。 Bill Curtis 制作了一份报告,虽然有点旧,但可能会有所帮助。他曾经(仍然是)一名心理学家。我会寻找引用他的研究论文(查看谷歌学者下的引文)。

It seems to me that the critical issues for designing a domain are its concepts and the relationships between them. This is covered by domain analysis, which it sounds like you have already done, but a key link anyway:

Guillermo Arango on Domain Analysis

With such analysis, you want to engineerin a domain, including a means of expressing problems and solutions. Wikipedia on Domain Engineering
was the obvious first place for this, but I found it very unsatisfying in that it failed to reference Arango's work.

(Arango was my officemate at UCI Irvine back in the 1980s, when domain analysis and engineering was a hot topic).

What you seem to want is human factors in langauge design. Bill Curtis produced a report, while a bit old, might be helpful. He was (still is) a psychologist. I'd look for research papers that referenced his (check out citations under google scholar).

給妳壹絲溫柔 2024-12-22 00:04:41

我读过 DSLs in Action (http://www.manning.com/ghosh/),他他出色地解释了有关编写 DSL 的不同问题,并在示例中使用了在 JVM 上运行的多种语言。

因此,您可能想检查一下,然后您可以查看他的参考资料以在您需要的地方获取更多信息。

I have read DSLs in Action (http://www.manning.com/ghosh/) and he did a fantastic job of explaining different issues regarding writing DSLs, and used several languages that run on the JVM in his examples.

So, you may want to check that out, and then you can look at his references to get more information where you need it.

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