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

1.1k views Asked by At

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

6

There are 6 answers

0
Dónal On BEST ANSWER

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.

2
McDowell On

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.

4
hallidave On
3
Bill K On

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.

0
Tom Hawtin - tackline On

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

0
Thorbjørn Ravn Andersen On

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?