Creating your own programming language can be a daunting task. After all, that's why developers choose existing programming languages, such as C#, Ruby, Perl, JavaScript or other traditional languages. However, in certain instances, a case may arise where non-developer business users may be required to configure and modify programming logic. Since not all business users can be programmers in the native programming language, it may be beneficial to implement a domain specific language that 3rd-party users can utilize. Simple examples of such a language might include Windows INI files or XML configuration files. However, we can create an even more specific custom programming language, just for our software purposes, by using an External Domain Specific Language.

...

In this article, we'll create our own simple programming language for mapping a dungeon role-playing game. Our language will consist of an external domain specific language, including types, source code sections, and strings. Our main program will load the external DSL code file into a state machine and execute the program, allowing us to walk through a deep, dank dungeon in search of treasure!

...

Sweeping the Dungeon Clean Similar to the above internal DSL, an example external domain specific language might appear as follows:

The above code requires no knowledge of C# .NET, nor any other programming language, and yet it allows the user to implement a fully operating program. The DSL created further down in this article will be similar to the above example, but we'll be adding an additional construct to include actions within a state.

...

Crawling the Dungeon Running the example program with our dungeon.txt code file produces the following output:

More episodes in this series

The Discussion

Billy McCafferty

Heh, the opening was hysterical...reminded me of my days of writing an RPG (based on D&D rules) on my TI-85 in AP Physics, junior year of high school. (In hindsight, probably should've paid more attention to the class.) Had to split it across two TI-85s due to the size of the program...part I and II with a transferrable data file to pick up where you left off in part II. Loved those days! (Later migrated it to Turbo Pascal.) Sure would've been easier with a Dungeon DSL!!Billyhttp://www.sharprobotica.com