I'm developing a desktop application that has as a requirement a window that allows the user to write/run small scripts that are interepreted (and can be written) at runtime (although they will also be able to save them for later use).
I've glanced at Groovy and Jython and am thinking I ought to be using one of these as opposed to creating my own "mini-language" (no matter how much that appeals to me). I'm curious as to what other people think is the best way to go about something like this. The language needs to be fairly simple/straightforward but I'd like give it as much flexibility/utility as java can give. The primary(possibly only) useage of the scripts will be for string manipulation and counting/simple arithmetic.
Any input or personal experiences that can help me avoid false starts etc would be greatly appreciated.
Of course if you were using a MS language Windows Scripting Host would be there awaiting your call. REXX was also designed expressly to be used this way, but never captured the developer community's heart. Either of these would take JNI from Java.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
definitely use an existing language instead of inventing your own, unless you're already an experienced language designer.
as for which one to pick, consider your user base. how experienced with programming are they likely to be? do they already have experience with some scripting language that's among your options, or that's very like one of your options? how much learning is it reasonable to ask them to do, and what language would most quickly get them up to speed with what they need to do with the least amount of learning required?
not knowing the answers to those questions, i'd recommend Jython. this mostly because i really like Python and think it is a very easy to learn language that's also easy and very quick to become productive in. it may or may not be the best fit for your user base, of course, but its string manipulation is excellent. slicing, splitting, rejoining, and interpolating strings is trivial in Python/Jython, and much nicer than in Java. for basic arithmetic, a dynamically-typed language like Python is just what you want; your users would seldom if ever have to worry about the "size" of their numbers, although they may have to consider the pitfalls of floating point versus integer math at times. [ May 24, 2005: Message edited by: M Beck ]
Joined: Nov 16, 2004
Well all the forseeable math would be simple integer arithmetic.
I'll take another look at Jython, the BeanShell looks interesting, and I know at least a few of the users will have java coding experience (so thats a plus).
thanks for the input.
Joined: Jan 29, 2003
Re doing your own ... can be great fun. P J Plauger once pointed out that nearly any data file can be thought of as implementing a language syntax, and nearly any data-driven program can be thought of as an interpreter. It's very easy to do sequential instructions and if-then-else. You can read lines and interpret them one at a time. Loops or callable routines or any kind of scoped blocks are much harder - you have to read and parse all the code and store it in some internal representation that you can bop around in. If you can get away with a very primitive language you can write your own interpreter with nothing much fancier than StringTokenizer.
subject: Desktop app with user interface for creating interepreted scripts...