Writing a domain specific language in c#

Download the VS project - KB Introduction Hello, and welcome to part two of this language implementation series. In part onea language most simple was defined in an attempt to introduce a method to parse source code into an Abstract Syntax Tree.

Writing a domain specific language in c#

Why this, and why now? To hear some people talk, you'd think DSLs solve world hunger, cure cancer, and make software write itself perhaps this is a bit of an exaggeration. DSLs are really nothing more than abstraction mechanisms. The current interest lies in the dawning realization that some abstractions resist easy representation in modern languages such as C.

writing a domain specific language in c#

For the last 20 years or so, developers have used objects as their primary abstraction mechanism. Objects work well because much of the world is hierarchical.

But edge cases still pop up. For example, consider the problem of querying relational data in a way that fits the object paradigm nicely. LINQ provides an elegant solution to that problem—and it's a DSL, one for building structured data queries in a way that fits in nicely with C.

A more formal definition appears later, but, for now, a working definition for a Domain Specific Language is that it's a computer language limited to a very specific problem domain. In essence, a DSL is an abstraction mechanism that allows very concise representations of complex data.

First, though, here are some term definitions. DSLs use language as an abstraction mechanism the way that objects use hierarchy. One challenge when talking about an abstraction mechanism as flexible as language lies in defining it. The thing that makes a DSL such a compelling abstraction is the parallel with a common human communication technique, jargon.

Here's a pop quiz. What "languages" are these? The first is easy: The second you probably know only if you eat at a Waffle House regularly: The Waffle House hash brown language consists of eight keywords, all transitive verbs: I hear something similar to the third example often because I have lots of colleagues who play cricket—but the language makes no sense to me.

And that's really the point: Consider the Waffle House example. Here's an alternative way to order hash browns: There is a plant called a potato, which is a tuber, a root plant.

Take the potato, harvest it, wash it off, and chop it into little cubes.

The Sample Problem

Put those in a pan with oil and fry them until they are just turning brown, and then drain the grease away and put them on a plate. OK, next I want cheese. There's an animal called a cow Don't ever try to order hash browns like this in a Waffle House because the person who's next in line will kill you.

All these examples represent jargon; common abbreviated ways that people talk.

Getting Started with Domain-Specific Languages - Visual Studio | Microsoft Docs

You could consider the Waffle House hash brown language as a domain specific language after all, it is a language specific to a domainbut doing so leads to a slippery slope where everything is a DSL.

A domain specific language is a limited form of computer language designed for a specific class of problems. He adds another related definition to this: Language-oriented programming is a general style of development which operates about the idea of building software around a set of domain specific languages.

With this definition in hand, I'll limit the scope of DSLs as a software terminology to keep it inside reasonable bounds.

C# - writing a portable domain specific language - Stack Overflow

Why use language as an abstraction mechanism?Domain Specific Languages are languages created to support a particular set of tasks, as they are performed in a specific domain. You could be familiar with the typical programming languages (a.k.a. General Programming Languages or GPLs).

In the first installment of this article, I showed how to leverage C# syntax to create a specific type of domain specific language in C# called a fluent interface, converting an API into something with a fighting chance of readability.

Domain Specific Languages (DSLs) have been a popular topic over the past couple years and will probably grow in importance in years to come. You might already be following the “Oslo” project (now called SQL Server Modeling) or experimenting with tools such as ANTLR to craft “external” DSLs.

There are plenty of ways to write a Domain Specific Language, but my advice is - don’t. What you would be doing is creating a language that no-one but a few people will know, and that could be a real problem to support in future. Domain Specific Language is a term that could indicate different things.

To me there are two families of domain-specific language: internal DSLs they basically are fluent interfaces.

writing a domain specific language in c#

You just use your language and try to create classes, functions and metaprogramming feature to create a way to express more clearly your intent. In this tutorial we develop an internal Domain Specific Language on ph-vs.com platform, including an editor with syntax highlighting and auto completion.

In addition to the method extensions that exist in C#, in Boo, it is also possible to add property extensions, as shown in the next example. Instead of writing .

Writing Your First Domain Specific Language, Part 1 of 2 - CodeProject