Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
From the book 1.7 Visualization

1.7 Visualization

One of the great advantages of a language workbench is that it enables you to use a wider range of representations of the DSL, in particular graphical representations. However, even with a textual DSL you can obtain a diagrammatic representation. Indeed, we saw this very early on in this chapter. When looking at Figure 1.1, you might have noticed that the diagram is not as neatly drawn as I usually do. The reason for this is that I didn’t draw the diagram; I generated it automatically from the Semantic Model (159) of Miss Grant’s controller. Not only do my state machine classes execute; they are also able to render themselves using the DOT language.

The DOT language is part of the Graphviz package, which is an open source tool that allows you to describe mathematical graph structures (nodes and edges) and then automatically plot them. You just tell it what the nodes and edges are, what shapes to use, and some other hints, and it figures out how to lay out the graph.

Using a tool like Graphviz is extremely helpful for many kinds of DSLs because it gives you another representation. This visualization representation is similar to the DSL itself in that it allows a human to understand the model. The visualization differs from the source in that it isn’t editable—but on the other hand, it can do something an editable form cannot, such as a render diagram like this.

Visualizations don’t have to be graphical. I often use a simple textual visualization to help me debug when I’m writing a parser. I’ve seen people generate visualizations in Excel to help them communicate with domain experts. The point is that, once you have done the hard work of creating a Semantic Model, adding visualizations is really easy. Note that the visualizations are produced from the model, not the DSL, so you can do this even if you aren’t using a DSL to populate the model.

  • + Share This
  • 🔖 Save To Your Account