对于现有的 Java 应用程序来说,什么是好的嵌入式语言?

发布于 2024-08-08 04:46:56 字数 589 浏览 5 评论 0原文

我想在我的应用程序中嵌入 dsl 或现有的完整语言。它应该是一种简单、完整的图灵完备语言,但又足够简单和轻便,可以在没有太多开销的情况下解释代码。

其他“进程”也不能影响任何其他进程。

我正在考虑使用 Clojure 并在 Clojure 代码上调用 Clojure 解释器/运行时编译器,但 Clojure 运行时花费的时间比我需要的要长得多。另外,我对于在这个项目中使用 Clojure 语言并不太兴奋。我的想法是更加程序化和类似 C 语言。

我考虑了 Ola Bini 的 Ioke 语言。 http://ioke.org/index.html

另外,我考虑过用 Scala 编写 DSL 吗?或者使用现有的 DSL。

更新:看起来 Rhino 是一个很好的嵌入式语言示例。

http://www.mozilla.org/rhino/tutorial.html

I want to embed a dsl or existing full language within my application. It should be a simple, full Turing complete language but simple and light enough that the code can be interpreted without too much overhead.

Also the other "processes" can't effect any other process.

I was considering using Clojure and invoking the Clojure interpreter/runtime compiler on Clojure code but the Clojure runtime takes a lot longer than I would need. Also, I am not overly excited of using the Clojure language for this project. I was thinking more procedural and C-like.

I considered Ola Bini's Ioke language. http://ioke.org/index.html

Also, I considered writing a DSL in Scala ? Or using an existing DSL.

Updated: It looks like Rhino is a good example embedded language.

http://www.mozilla.org/rhino/tutorial.html

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

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

发布评论

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

评论(6

街角卖回忆 2024-08-15 04:46:56

Groovy 的动态特性非常适合编写 DSL。事实上,有大量由 Grails Web 框架实现的 Groovy DSL,以及大量教授如何使用 Groovy 编写 DSL 的教程和书籍。

此外,Groovy 的语法几乎是 Java 语法的超集,因此它应该相对容易掌握(与 Clojure 相比)。 Java 和 Groovy 代码之间的调用是无缝的,因此您可以在 Groovy 代码中轻松使用所有您喜欢的 JDK 类。

我倾向于避免使用 IOKE,因为它还不成熟,并且出于 DSL 的目的,我认为像 Groovy 或 JavaScript 这样的动态类型语言是比 Scala 更好的选择。

Groovy's dynamic nature is ideally suited to writing DSLs. Indeed there are a large number of Groovy DSLs implemented by the Grails web framework, and plenty of tutorials and books that teach how to write DSLs with Groovy.

Also, Groovy's syntax is almost a superset of Java's, so it should be relatively easy to pick up (compared to Clojure). Calling between Java and Groovy code is seamless, so you can easily use all your favourite JDK classes within Groovy code.

I'd be inclined to avoid IOKE on account of it's immaturity and for the purpose of a DSL, I think a dynamically typed language like Groovy or JavaScript is a better choice than Scala.

反话 2024-08-15 04:46:56

我建议Java。它是:众所周知、快速、易于与 Java 集成、稳定、静态类型、易于迁移代码等等。

I suggest Java. It's: well known, fast, easy to integrate with Java, stable, statically typed, easy to migrate code, etc., etc.

好久不见√ 2024-08-15 04:46:56

查看 scripting.dev.java.net 以获取用于在您的应用程序中嵌入其他语言的脚本引擎列表Java 应用程序。请注意,一些引用的语言现在附带了自己的 JSR 223 集成,因此不需要第 3 方库来使用它们。

Check out scripting.dev.java.net for a list of Script Engines for embedding other languages in your Java applications. Note that some of the referenced languages now ship with their own JSR 223 integration, so there's no need for a 3rd party library to use them.

萌酱 2024-08-15 04:46:56

如果您想要 DSL,那么您并不是真的想嵌入现有语言,而是想创建一种“领域特定语言”。对我来说,这不仅仅意味着更改一些关键字和不使用括号。

例如,现在我正在从事电视调度工作。当我们为测试创建假指导数据时,我们总是添加一条如下所示的注释(直接从我正在处理的测试中切出):

 * TIME:8.....30....9.....30....10....30....11....30....12....30....
 * 4FOX:____________[Spotlight.............][Jeopardy..]____________
 * 6CBS:[Heroes....][Heroes....][Heroes....]________________________
 * 8HMK:xx[A.River.Runs.Through.It....][Blades.Of.Glory...]_________

如果我必须创建更多指导数据,我将直接将这些注释解释为DSL(使它们成为长字符串或字符串数​​组而不是注释)。

这将是一个合适的 DSL。

如果您刚刚嵌入一种灵活的语言,Groovy 或 JRuby 都是为此而设计的,BeanShell 也是如此。

事实上,有一个完整的 API 围绕可替换的插件脚本语言构建,因此您应该能够放入任何您想要的 JVM 语言,而无需更改您的代码。

If you want a DSL, then you don't really want to embed an existing language, you want to create a "Domain Specific Language". To me that means a lot more than just changing some keywords and not using parenthesizes.

For instance, right now I'm working on TV Scheduling right now. When we create fake guide data for a test, we always add a comment that looks like this (cut directly out of the test I'm working on):

 * TIME:8.....30....9.....30....10....30....11....30....12....30....
 * 4FOX:____________[Spotlight.............][Jeopardy..]____________
 * 6CBS:[Heroes....][Heroes....][Heroes....]________________________
 * 8HMK:xx[A.River.Runs.Through.It....][Blades.Of.Glory...]_________

If I have to create more guide data, I'll directly interpret those comments as a DSL (Making them a long string or string array instead of comments).

That would be an appropriate DSL.

If you're just after embedding a flexible language, Groovy or JRuby are both made for this, as is BeanShell.

There is, in fact, an entire API built around replaceable plug-in scripting languages so that you should be able to drop in any JVM language you want and not change your code a bit.

打小就很酷 2024-08-15 04:46:56

根据您的规范,一个小型的 BrainF*ck 解释器应该没问题:)

如果这不是您想要的,那么请考虑您想要解决的问题。您的案例研究是什么?是否能够稍后随意添加新代码,而无需重新部署应用程序的新版本?

A small BrainF*ck interpreter should be fine according to your spec :)

If it is not quite what you had in mind, then consider what it is you want to solve. What is your case study? Is it to be able to add new code at will later without having to redeploy a new verison of your application?

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