简体   繁体   English

什么是现有Java应用程序的良好嵌入式语言?

[英]What is a good embeddable language for an existing Java application?

I want to embed a dsl or existing full language within my application. 我想在我的应用程序中嵌入dsl或现有的完整语言。 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. 我正在考虑使用Clojure并在Clojure代码上调用Clojure解释器/运行时编译器,但Clojure运行时需要比我需要的时间长得多。 Also, I am not overly excited of using the Clojure language for this project. 此外,我对使用Clojure语言进行此项目并不过分兴奋。 I was thinking more procedural and C-like. 我在考虑更多程序性和C类。

I considered Ola Bini's Ioke language. 我考虑过Ola Bini的Ioke语言。 http://ioke.org/index.html http://ioke.org/index.html

Also, I considered writing a DSL in Scala ? 另外,我考虑在Scala中编写DSL? Or using an existing DSL. 或者使用现有的DSL。

Updated: It looks like Rhino is a good example embedded language. 更新:看起来Rhino是一个很好的示例嵌入式语言。

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

Groovy's dynamic nature is ideally suited to writing DSLs. Groovy的动态特性非常适合编写DSL。 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. 事实上,Grails Web框架实现了大量Groovy DSL,以及大量教程和书籍,教授如何使用Groovy编写DSL。

Also, Groovy's syntax is almost a superset of Java's, so it should be relatively easy to pick up (compared to Clojure). 另外,Groovy的语法几乎是Java的超集,所以它应该相对容易上手(与Clojure相比)。 Calling between Java and Groovy code is seamless, so you can easily use all your favourite JDK classes within Groovy code. 在Java和Groovy代码之间调用是无缝的,因此您可以轻松地在Groovy代码中使用所有您喜欢的JDK类。

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. 我倾向于避免IOKE因为它不成熟而且出于DSL的目的,我认为像Groovy或JavaScript这样的动态类型语言是比Scala更好的选择。

I suggest Java. 我建议Java。 It's: well known, fast, easy to integrate with Java, stable, statically typed, easy to migrate code, etc., etc. 它是:众所周知,快速,易于与Java集成,稳定,静态类型,易于迁移的代码等,等等。

Check out scripting.dev.java.net for a list of Script Engines for embedding other languages in your Java applications. 查看scripting.dev.java.net以获取用于在Java应用程序中嵌入其他语言的脚本引擎列表。 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. 请注意,一些引用的语言现在附带了自己的JSR 223集成,因此不需要第三方库来使用它们。

If you want a DSL, then you don't really want to embed an existing language, you want to create a "Domain Specific Language". 如果你想要DSL,那么你真的不想嵌入现有的语言,你想要创建一个“领域特定语言”。 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). 如果我必须创建更多的指南数据,我会直接将这些注释解释为DSL(使它们成为长字符串或字符串数​​组而不是注释)。

That would be an appropriate DSL. 这将是一个合适的DSL。

If you're just after embedding a flexible language, Groovy or JRuby are both made for this, as is BeanShell. 如果您刚刚嵌入了一种灵活的语言,Groovy或JRuby都是为此而设计的,就像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. 事实上,有一个完整的API围绕可替换的插件脚本语言构建,因此您应该能够使用任何您想要的JVM语言,而不是稍微更改您的代码。

A small BrainF*ck interpreter should be fine according to your spec :) 一个小的BrainF * ck翻译应该没问题,根据你的规格:)

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? 是否能够在以后随意添加新代码而无需重新部署应用程序的新版本?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM