Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm debating designing a domain specific language to simplify a given, obscure programming model. Part of the debate is whether to build it (as a script) atop an existing language/runtime (e.g. Java) or to make it stand-alone (own compiler, &c).

Those of you with DSL design experience, do you have pros/cons and or a sure-fire answer to the appropriate approach?

share|improve this question
    
who's the consumer of this DSL? and what are the potential hosts (you mentioned Java, are you considering other possibilities)? –  Mauricio Scheffer Jan 24 '11 at 5:27
    
I consider any possibility for the hosts. Consumer will be those writing asynchronous programs (messages with destinations). –  Xepoch Jan 24 '11 at 5:47
add comment

4 Answers

up vote 6 down vote accepted

I would recommend creating your DSL on top of an existing language (internal DSL). I've done this a few times with Python, creating systems where the consumer of the DSL writes a python file that is used as a configuration file for the system. The configuration file uses constructs (classes, functions) that I have defined. These constructs form the DSL.

IMO, a language like Python (IronPython or Jython if the host system is .NET or Java) or Ruby (IronRuby, JRuby) is better for basing your DSL on than Java or C#.

In my case the host systems has also been (C)Python, so choosing Python for the DSL has been the natural thing.

Some pros:

  • Lower cost of building. There is a lot less for you to implement. You can focus on the problem at hand instead of spending time to implement a parser/compiler/interpreter.
  • Access to the host language: Your language will have access to the full power of the existing language/platform.
share|improve this answer
    
I'm pretty language agnostic, but why do you think Python incarnations are better suited? –  Xepoch Jan 24 '11 at 23:11
1  
Better suited than what? I guess Ruby and Python have many of the same benefits, Ruby is maybe even better suited for internal DSL because of its more flexible syntax. As for Java and C#, I've seen many a fine fluent interface in those languages (and there are constructs in newer versions that make internal DSL creation/use easier, like object initializer syntax) - but IMO the "low ceremony" languages are slightly better suited than "high ceremony" languages. –  codeape Jan 25 '11 at 9:19
add comment

Look at Xtext (http://www.eclipse.org/Xtext/) and Xbase (http://blog.efftinge.de/2010/09/xbase-new-programming-language.html). If the users are non programmers I don't think you should base your DSL on an existing programming language. It will be too complicated for them. A "clean" DSL can be very efficient if made correctly.

share|improve this answer
add comment

Rather than recommending a particular approach, allow me to recommend Martin Fowler's Domain-Specific Languages as an excellent resource for making the decision. It has an extensive, thought-provoking examination of the relative merits of internal and external DSLs.

share|improve this answer
add comment

There is a third option - build a DSL as a compiler atop of a general purpose language. Any language with some reasonable degree of metaprogramming capabilities will do the job, including even such a low-level thing as C++. I prefer Lisp and similar languages for this kind of things, but Template Haskell or Nemerle could provide the same level of flexibility as well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.