Question

Couldn't a DSL be as simple as an API and therefore not need a parser? Or am I misunderstanding what a domain specific language really is? I thought it referred to any organized set of rules for solving a particular domain problem. An API would seem to fit that definition, right?

Was it helpful?

Solution

You can embed a DSL within a more general programming language. This is often a good solution. (You could say that this DSL takes the form of a particular API.)

You can also create a separate language, with its own interpreter, to represent the concepts of your domain. This tends to be a larger undertaking, and is often not necessary.

OTHER TIPS

You're confusing the concept with the implementation. A domain-specific language is any representation of an idea that is considered "close" to the problem domain, rather than being a general language for the description of solving problems in general.

Yes, a DSL might be implemented as an API, which provided functions that referred to particular concepts in the problem domain, but a DSL is equally valid when represented as a text file.

The Pragmatic Programmer: From Journeyman to Master contains a good description of DSLs and the circumstances in which they're useful, with examples. Highly recommended.

You would still have only the semantics of the host-language.

E.g.: functional programming in an imperative language does not work. So you have a functional DSL added to this imperative language ...

Yes, absolutely - a mere API will do nicely as a DSL if the host language has sufficient flexiblity to support it.

Ruby is a very good language for such, particularly given the optional parens and other flexibilities.

  • Rails is often referred to as a DSL for writing database-driven web applications.

  • Rake is a build system with a DSL for writing (smarter) makefiles.

My own OOFILE is a framework you can regard as a DSL for writing database applications in C++ - it was inspired by dBase and makes very heavy use of C++ operator overloading, local objects and stream idioms.

Forth is classically a language which blurs the line between DSL and API as a Forth program consists of little more than a series of space-separated words. Probably the most impressive example of a Forth DSL is Abundance - Abundance is a Forth-based business programming language, written in BBL Forth. BBL is a 32 bit DOS FORTH compiler. Distributed as is. See the warnings. This is not for the faint hearted. It would be of interest mainly to someone developing software for the third world where you need fast execution on old klunker XT and AT computers. You can write some very sophisticated data entry programs with it that will run circles around modern data entry programs.

And of course, a graphical DSL would require no parsing at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top