page1
A Domain-Specific Language for Interactive Fiction
Evan Silberman, TJHSST Computer Systems Lab, 2006-07
Abstract
A domain-specific language (DSL) is a programming language designed to be used for a specific and limited set of tasks. Using metaprogramming techniques, I designed IFAlpha, a DSL hosted within Ruby for creating interactive fiction games. My goal was to create an intuitive and expressive language for creating IF games while hiding the details of implementation from the programmer.
#example 1
room :living do
name “Living room”
desc “This is not tom's favorite room”
exit :north, :fantasy
end
Methods
Metaprogramming is simply the technique of writing code that writes code. The Ruby programming language contains extensive built-in facilities for metaprogramming that faciltated my design goals. Instance_eval is a method which every Ruby Object has which takes a code block, then evaluates that code block as if the methods in it were instance methods of that object. This allows the syntax wherein details of a room are declared without the programmer knowing anything about the Room class. The method_missing method, which is called on an object when no instance method exists, allows the programmer to define arbitrary properties to be dealt with later for the rooms they create.
Ease of Use
The principle design goal of the language is ease of use. Users learned how to use the language first by modifying the example game provided, then creating their own games. IFAlpha was reported by users to be fun and easy to use. Though implementing the full range of features one might expect from an interactive fiction game engine proved to be infeasible, the features that were implemented were determined to be natural to use and easy to understand. The project was a success.
Design Goals
Ease of use
Clarity of syntax
Appropriate expressiveness
Hiding the implementation
Programmer defines
a room in the
game file
Shell interprets
user commands and
interacts with
backend
Backend instantiates
a new Room object
with the specified
properties
User interacts
with shell