Create DSL and implement an existing language

This often arises: your application has gained extensive access to add some programmability to it to make it flexible. One example would be a funding application β€” you want to add a formula editor so you can create your own formulas without having to recompile the code.

You have to make a choice: do you create your own tokenizer, parser and compiler interpreter / chain, which can take a lot of time and can be done wrong? Or you just insert another scripting language that has the problem that it probably inflates your code and exposes your application to security vulnerabilities.

How would you balance the compromises and make this decision?

+4
source share
4 answers

Refusal of the transaction - implement a proven, well-documented interpreter. Otherwise, you will have such an abomination as MAXScript.

+3
source

How about a plug-in system? There are several advantages:

  • Allow client developers to develop in the environment in which the original application is developed.
  • In modern dev. platforms, you get a lot of control and security through software contracts.
  • If it is designed correctly, you can correctly blame the bloat and damage to the plug-in that caused it β€” for example, Chrome, when Flash or another third-party plug-in crashes.
  • Easily add additional protection through licensing / certificates.
  • It's easy to combine the plug-in with the app if it's awesome and you want all your clients to have it.
+2
source

If the DSL is simple enough so that the parser / interpreter matches a single page, I would recommend implementing an existing scripting language.

I recently worked on a project that I inherited for several months, which contained the completely native scripting language. I spent a lot of time understanding the parser and the interpreter so that I can correct errors, make it thread safe, expand it, and optimize. In addition, there was time to learn and understand the quirks of this new scripting language, which were almost the same as the others that I already knew. I would prefer to use this time to embed an existing language such as Ruby or Lua, and customize it to suit our needs.

The user could use a language that was easier to program with less quirks and errors. I would take a deeper understanding of the internal components of a well-designed and popular language, rather than gaining relative useless expertise in "myScript".

+1
source

I would create my own interpreter using an existing parser generator (e.g. ANTLR or Haskell / Scala parser compilers). It really is not as difficult as all this, and for simple languages ​​it is very easy. I create an implementation for the devilishly simple DSL at noon, and it works great the first time (no errors).

With this in mind, you do not want to create your own Turing Complete language. If your needs are so complex, you should probably include a scripting language. If you work in the JVM, JRuby and Clojure are great candidates for such things, especially considering their own advantages in the field of internal DSL.

0
source

All Articles