Lots of people like Groovy and/or JS but I don't. I don't think JS is very maintainable and Groovy is a lot of syntactic sugar based upon dubious decisions in my experience.
However, that is the key. I was asked to translate something similar for a company and they wanted Groovy as output. But the problem with such translations is that because Groovy will almost certainly not behave like your existing script/code, you will find yourself wrapping what would be otherwise simple expressions in strange looking method calls. For instance if +, / don't give exactly the same results as Groovy, then you will need to write methods that simulate the results from your DSL's runtime.
Basically, you will get a mess. The company in question would not believe me until they started to see the output. Then we changed to a better DSL that translated to JVM byte code and ran in the Java JVM with some runtime routines.
Either just starting again with a new DSL and rewriting the current source or translating the current source to your new DSL. BUt translating the existing code to a new DSL is probably the best bet, getting rid of this snippets of code stored in database tables.
It depends what you can run in your software stack, but if the JVM is not an issue, then your DSL would generate JVM byte codes (not very difficult - you use the ASM library to do this), or if you can't be bothered with that, then just generate Java code and compile that in the background. You will likely need a small runtime library jar that supports the idioms of your language.
It sounds like the language you have gets the job done, but organizationally and syntactically it is a mess. So it seems you need a 're-assembler' that starts with the base code snippets, replaces the insert points with the relevant snippets so you have a source, then a translator to the new DSL and a parser for the new DSL. The translator and parser will probably the least of your issues.
One possible problem I can see for you is that the interpreter may do this snippet replacement dynamically. As in when you run it with one set of inputs it uses snippet A from the database but a different set of inputs uses snippet B. In other words it will have to be interpreted unless you can somehow predict all possible paths in the interpreter and generate if statements or switch statements to cover them. If it starts to get that complicated then I think it is likely better to throw it away and start again, maybe with a DSL or maybe you just bite the bullet and write that logic from scratch in something that you want.
Assuming that the programs do not change dynamically (but I am willing to bet, given how you say it is put together, that they do), then:
- With all baselilne/startpoints - use an 'assembler' to put together the source that runs as a a blob
- Use ANTLR to translate this to a new DSL form
- Eventually, throw those tools away
- Use ANTLR to write a new compiler for your code and generate java or java byte code (you can of course pick anything)
- Run the byte code in your stack
Without more information on what this does at runtime/interpretation time, I can't begin to guess if it is even translatable in a static form.
Jim