在Java上使用DSL的第一步? [英] First Steps with DSL on Java?

查看:850
本文介绍了在Java上使用DSL的第一步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们……女孩们,我正在一个项目上,我认为可以通过实现一种领域特定语言来增强,该语言为某种类型的工作流程定义一套规则和/或条件.

Guys... Girls, I'm working on a project which I think could be enhanced by implementing a Domain Specific Language for defining a set of rules and/or conditions for some type of work-flow.

我想牢牢掌握主题,基础知识,最佳实践等,尤其是如何使用Java来实现它们.

I want to get a firm grasp on the subject, fundamentals, best practices, etc. specially how to implement them somehow with Java.

您有什么建议?

推荐答案

首先,我建议阅读 Kernighan和Pike的编程实践.

完成此操作后,请回到此处,提出有关如何将本章中的概念映射到特定设计以解决您要解决的问题的特定问题.

When you have done that, come back here with specific questions on how to map the concepts in that chapter to specific designs for the problems you want to solve.

基本模式是编写一个解释器,该解释器将传递一个命令"自变量,并可能传递一个环境"自变量并在环境中执行该命令.然后,您可以选择编写一个解析器,该解析器接受一个脚本"字符串并将其转换为有效的命令"对象(例如,外部DSL).或者您提供一个库来帮助用户以您使用的相同语言(内部DSL)显式地构建命令"对象.

The basic pattern is to write an interpreter that is passed a 'command' argument, and possibly an 'environment' argument and executes the command (in the environment). You then have the option of writing a parser, that takes a 'script' string and converts it into a valid 'command' object (ie. an external-DSL); or you provide a library to help users build the 'command' object explicitly in the same language you are using (internal-DSL).

Kernighan和Pike很好地展示了口译员的琐碎和复杂程度.如果您想更深入,那么我建议您阅读编程基础语言,作者:丹尼尔·弗里德曼(Daniel Friedman)等.每章至少构建一个不同的解释器,并演示如何实现诸如变量,函数,范围,对象,类,静态类型和延续之类的功能.

Kernighan and Pike do a good job of showing both how trivial and how complex an interpreter can be. If you want more depth, then I would suggest reading The Essentials of Programming Languages by Daniel Friedman et al. Which builds at least one different interpreter per chapter, and demonstrates how to implement features such as variables, functions, scopes, objects, classes, static-typing, and continuations.

但是,我建议您先尝试一下普通的DSL,否则就只是理论问题了-如果您根据以前的经验将其变得实用和实用,这本书会变得更加有趣.

However I would suggest trying your hand at a trivial DSL first, otherwise it's all just theory—a book is much more interesting when it is made relevant and practical by your previous experience.

这篇关于在Java上使用DSL的第一步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆