Domain-Specific Languages 23

2023-10-27

Domain-Specific Languages
Whenever you listen to a discussion by experts in any domain, be it chess players, kindergarten teachers, or insurance agents, you’ll notice that their vocabulary is quite different from everyday language. That’s part of what domain-specific languages (DSLs) are about: A specific domain has a specialized vocabulary to describe the things that are particular to that domain.

In the world of software, DSLs are about executable expressions in a language specific to a domain with limited vocabulary and grammar that is readable, understandable, and — hopefully — writable by domain experts. DSLs targeted at software developers or scientists have been around for a long time. For example, the Unix ‘little languages’ found in configuration files and the languages created with the power of LISP macros are some of the older examples.

DSLs are commonly classified as either internal or external:

Internal DSLs are written in a general purpose programming language whose syntax has been bent to look much more like natural language. This is easier for languages that offer more syntactic sugar and formatting possibilities (e.g., Ruby and Scala) than it is for others that do not (e.g., Java). Most internal DSLs wrap existing APIs, libraries, or business code and provide a wrapper for less mind-bending access to the functionality. They are directly executable by just running them. Depending on the implementation and the domain, they are used to build data structures, define dependencies, run processes or tasks, communicate with other systems, or validate user input. The syntax of an internal DSL is constrained by the host language. There are many patterns — e.g., expression builder, method chaining, and annotation — that can help you to bend the host language to your DSL. If the host language doesn’t require recompilation, an internal DSL can be developed quite quickly working side by side with a domain expert.

External DSLs are textual or graphical expressions of the language — although textual DSLs tend to be more common than graphical ones. Textual expressions can be processed by a tool chain that includes lexer, parser, model transformer, generators, and any other type of post-processing. External DSLs are mostly read into internal models which form the basis for further processing. It is helpful to define a grammar (e.g., in EBNF). A grammar provides the starting point for generating parts of the tool chain (e.g., editor, visualizer, parser generator). For simple DSLs, a handmade parser may be sufficient — using, for instance, regular expressions. Custom parsers can become unwieldy if too much is asked of them, so it makes sense to look at tools designed specifically for working with language grammars and DSLs — e.g., openArchitectureWare, ANTlr, SableCC, AndroMDA. Defining external DSLs as XML dialects is also quite common, although readability is often an issue — especially for non-technical readers.

You must always take the target audience of your DSL into account. Are they developers, managers, business customers, or end users? You have to adapt the technical level of the language, the available tools, syntax help (e.g., intellisense), early validation, visualization, and representation to the intended audience. By hiding technical details, DSLs can empower users by giving them the ability to adapt systems to their needs without requiring the help of developers. It can also speed up development because of the potential distribution of work after the initial language framework is in place. The language can be evolved gradually. There are also different migration paths for existing expressions and grammars available.

By Michael Hunger
领域特定语言
每当你听任何领域的专家的讨论,无论是棋手、幼儿园老师还是保险代理人,你都会注意到他们的词汇与日常语言截然不同。这就是领域特定语言(DSL)的一部分:一个特定的领域有一个专门的词汇表来描述该领域特有的东西。在软件世界中,DSL是指特定于词汇和语法有限的领域的语言中的可执行表达式,该语言可由领域专家阅读、理解,并有望写入。针对软件开发人员或科学家的DSL已经存在很长时间了。例如,配置文件中的Unix“小语言”和使用LISP宏创建的语言是一些较老的例子。DSL通常分为内部或外部:内部DSL是用一种通用编程语言编写的,其语法已经被弯曲,看起来更像自然语言。这对于提供更多语法糖和格式化可能性的语言(例如Ruby和Scala)来说比其他不提供语法糖和格式可能性的语言更容易(例如Java)。大多数内部DSL封装现有的API、库或业务代码,并提供一个封装器来减少对功能的访问。只要运行它们,它们就可以直接执行。根据实现和域的不同,它们用于构建数据结构、定义依赖关系、运行流程或任务、与其他系统通信或验证用户输入。内部DSL的语法受到主机语言的限制。有许多模式——例如,表达式构建器、方法链接和注释——可以帮助您使宿主语言适应DSL。如果宿主语言不需要重新编译,那么可以很快地与领域专家一起开发内部DSL。外部DSL是语言的文本或图形表达——尽管文本DSL往往比图形DSL更常见。文本表达式可以由一个工具链处理,该工具链包括lexer、解析器、模型转换器、生成器和任何其他类型的后处理。外部DSL大多被读入内部模型,这些模型构成了进一步处理的基础。定义语法是有帮助的(例如,在EBNF中)。语法为生成工具链的各个部分(例如编辑器、可视化工具、解析器生成器)提供了起点。对于简单的DSL,手工解析器可能就足够了——例如,使用正则表达式。如果对自定义解析器的要求太高,它们可能会变得很难使用,因此查看专门为处理语言语法和DSL而设计的工具是有意义的,例如openArchitectureWare、ANTlr、SableCC、AndroMDA。将外部DSL定义为XML方言也是很常见的,尽管可读性通常是一个问题,尤其是对于非技术读者来说。您必须始终考虑DSL的目标受众。他们是开发人员、经理、业务客户还是最终用户?您必须调整语言的技术水平、可用的工具、语法帮助(例如intellisense)、早期验证、可视化和表示以适应预期受众。通过隐藏技术细节,DSL可以让用户在不需要开发人员帮助的情况下根据自己的需求调整系统,从而增强用户的能力。它还可以加快开发,因为在初始语言框架到位后,工作可能会分布。这种语言可以逐渐演变。现有的表达式和语法也有不同的迁移路径。作者:Michael Hunger

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Domain-Specific Languages 23 的相关文章

  • minikube 快速使用入门 - 安装 - 1

    minikube的官网地址 Welcome minikube k8s io minikube是什么 Minikube是一个单机版的kubernetes集群 可以在windows mac linux 快速的创建一个kubernetes集群 它
  • 原来react的createContext 这么简单

    今天看了下react中createContext相关的源码 特意在这里拿出来分享下 同时也会体现出关于本人看源码的技巧 本文采用源码分析以及源码断点调试的方式进行列举 用法 import React from react const Cou
  • (转)解决windows10下无法安装.net framework 3.5,错误代码0x800F081F

    1 下载 NET Framework 3 5的安装包netfx3 cab 将下载的文件复制到复制到 C 盘的 Windows 文件夹 后请在 命令提示符 管理员 中执行下面的命令 dism online Enable Feature Fea
  • centos下离线安装PostgreSQL

    安装简述 1 配置系统环境 2 安装postgreSQL 3 创建用户和分配权限 4 设置远程连接 配置系统环境 前提条件 文件postgresql 12 2 tar gz 放在 opt路径 步骤1 解压文件 cd opt tar zxvf
  • 编译错误记录

    一 MDK编译错误 1 error 235 variable epos msg was declared with a never completed type 这个错误的意思是epos msg这个变量被一个 没有被完成的的类型 定义 原因
  • Android串口通讯SerialPort(使用篇)

    1 什么是串口 在不会使用串口通讯之前 暂且可以把它理解为 一个可通讯的口 使用篇不深入探讨理论及原理 能理解串口如何使用之后 可以查看Android串口通讯SerialPort 浅谈原理 2 添加依赖 1 在 module 中的 buil

随机推荐

  • 数据库学习笔记之数据查询(一)

    数据库学习笔记之数据查询 一 查询之前先添加几条数据叭 还是基于这个里面建的那三个表 Student Course SC 进行插入查询操作 数据都是书上的 为Student表添加数据 INSERT INTO Student VALUES 1
  • pip install requests 报错 Could not fetch URL https://pypi.python.org/simple/requests/: There was ..r

    如题 pip install requests 报错 Could not fetch URL https pypi python org simple requests There was a problem confirming the
  • pandas读写mysql、h2和oracle数据库

    pandas读写mysql h2和oracle数据库 一 mysql数据库 二 h2数据库 三 oracle数据库 前言 在机器学习过程中 除开自己导入数据 用pandas的read xx之外 很多时候同样需要从数据库导入数据 特别是在做工
  • 夜莺(Flashcat)V6监控(五):夜莺监控k8s组件(下)---使用kube-state-metrics监控K8s对象

    目录 一 前言 二 categraf作为Daemonset的方式去运行监控k8s组件 1 1 24版本以下的k8s集群部署方法 创建autu yaml绑定权限 Daemonset部署categraf采集监控kubelet kube prox
  • 在jsp页面获取url请求参数

    JSP页面 When using the JSTL s expression language the request parameters are made available in the implicit object param T
  • css flex布局 —— 项目属性 flex-grow

    flex grow 属性定义项目的放大比例 解决的问题是 在空间有多余时把多余空间分配给各个子元素 flex grow 的值默认为 0 也就是说 如果存在剩余空间 也不放大 flex grow 取值为非负数 如果取值为负数那么和0的取值效果
  • mybatis拦截器

    最近在用mybatis做项目 需要用到mybatis的拦截器功能 就顺便把mybatis的拦截器源码大致的看了一遍 为了温故而知新 在此就按照自己的理解由浅入深的理解一下它的设计 和大家分享一下 不足和谬误之处欢迎交流 直接入正题 首先 先
  • 踩坑将一个AndroidStudio项目变成一个module引入到自己的项目中

    最近工作中遇到了需要将一个完整的androidstudio项目移植到自己项目中去 因为考虑到自己已经有的项目和需要引入的项目资源都很庞大 为了方便代码管理 决定将需要引入的项目作为一个module导入到自己现有项目中来 操作步骤 1 在主项
  • Cookie 与 Session 的作用及区别

    Cookie Cookie 其实就是客户端储存的 什么是客户端 就是浏览器存储 能看的见的 在浏览器设置 历史纪录中能看见 能手动清除Cookie 所以它一般都会被用在不重要的地方 因为它很容易被发现 cookie以明文储存信息 而且储存量
  • unity中lightProbe的使用

    之前曾经介绍过Unity3D的LightMapping烘焙的用法 单独使用的LightMapping效果很好 但由于只是把光影烘焙到贴图上面 所以并不会对周围的动态物体产生真正的光照效果 这次来介绍一下LightProbe 这是对Light
  • 服务器小程序空间,服务器空间-小程序-建站-企业邮箱

    Your twitter username username wange1228 Prefix some text you want displayed before your latest tweet HTML is OK but be
  • 华为OD机试 - 单词倒序(Java)

    题目描述 输入单行英文句子 里面包含英文字母 空格以及 三种标点符号 请将句子内每个单词进行倒序 并输出倒序后的语句 输入描述 输入字符串S S的长度 1 N 100 输出描述 输出倒序后的字符串 备注 标点符号左右的空格 0 单词间空格
  • C语言 -- 动态数组&链表

    目录 动态数组 动态数组的实现 用户test 链表 目的 链表的结构体 链表的实现 初始化链表 插入节点 遍历链表 删除节点 清空链表 销毁链表 用户回调函数 给用户提供接口获取链表长度 用户test 动态数组 将数组开辟到堆区 实现动态扩
  • ubuntu 16.04安装 jdk 1.9

    1 命令行输入javac 提示java尚未安装 选择提示中的包进行安装 2 执行 sudo apt install 安装jdk的版本号 根据提示确认安装 3 配置jdk路径 执行 sudo gedit etc profile 输入密码打开文
  • c++ STL vector知识点

    c 知识点 vector基本概念及定义 vector函数的构造 vector函数实现 vector基本概念及定义 头文件 include
  • VTK入门001——HelloVTK

    include VTKPlatform h vtkConeSource 是 VTK 库中的一个类 用于生成一个圆锥体的几何形状 include
  • 网站数据分析报告怎么写?

    网站数据分析报告怎么写 1 目标 Objective 是前提 网站分析报告的起点不是从现象开始的 而是从网站的目标 objective 开始的 我相信大多数网站的目标不应该超过1个 那些各种目标都应该归结为一个最终的最根本的目标 如果你的老
  • CTF show 萌新web-1

    首先看题目 代码整体逻辑是先通过GET请求传递参数id 如果id大于999 报错 如果小于999 则输出当前的执行的sql语句 如果根据id参数能在数据库中查到值 row 则将其打印出来 而flag则是id为1000的 row中的内容 这道
  • excel表格(.csv)保存到数据库--QT数据库

    刚学QT的菜鸟 无聊的时候总会找一点事情做 言归正传 将excel表格保存到数据库 是比较简单的 我的想法简单粗暴 从路径中获取文件 通过按键控制加载 将大象放进冰箱需要是三步 这个同样 1 获取路径 2 读取Excel文件 3 将其保存到
  • Domain-Specific Languages 23

    Domain Specific Languages Whenever you listen to a discussion by experts in any domain be it chess players kindergarten