Bridging the gap between Modelling and Programming with XMF and XModeler

Today we have a guest post by Tony Clark where he introduces us to his innovative XMF and XModeler tools for bridging the gap between modeling and programming. Enjoy!

Modelling and programming have traditionally been seen as separate activities. Their respective technologies tend not to integrate. This is frustrating because models usually represent executing systems and programming languages need to provide features that map onto concepts from problem domains. This leads to a gap between models and programs that model-driven techniques seek to bridge. There are a number of ways in which this gap could be addressed:

o Modelling languages can be made executable so that they completely address the systems they are used to represent. It is easier to map a complete model to an implementation than an incomplete one.

o Languages can be made flexible so that domain specific features can be directly represented and thereby close the conceptual gap between the problem domain and its representation, or a model and its implementation.

o Programming languages can subsume models so that programming and modelling are performed using the same platform. Programs can easily reason about, manipulate and transform models.

o Both modelling and programming technologies can be organized in terms of meta-architectures that support reflection and meta-level extensions. General purpose features can co-exist with specialized language constructs.

XMF and XModeler were designed to address these issues.

XMF

XMF is a programming language designed to support meta-programming and domain specific languages. XMF runs on a VM written in Java in terms of a self-describing data-model. The key features of XMF data are shown as a class diagram in XModeler as:

The XMF data model is similar to MOF and ECore in that you can write programs that reflect on their own structure. Unlike MOF and Ecore, the XMF kernel meta-model includes behaviour defined by the classes Operation and Performable.

XMF is both a compiled and interpreted language (like Lisp and Smalltalk) where both the compiler and the interpreter are written in XMF. The basic language included with XMF is based on OCL with the following differences:

Higher-order functions: functions make it easy to define general-purpose data transformations. OCL iterators are encoded using functions in XMF.

Variables and update: the addition of state to OCL turns it into a convenient very high-level programming language. If you use XMF to do modelling then you can ignore this feature.

Pattern matching: data can be matched and deconstructed using patterns. This is used extensively in model transformations.

The XMF VM supports the following features:

IO: XMF uses a variety of channels that work in the same way as Java streams. The IO package in XMF provides extensive support for serializing data, for example as XML.

Foreign Functions: it is easy to load Java classes and make them work as though they are XMF classes.

Threads: used, for example, in socket connections.

Daemons: used to monitor changes to slot values on any object.

A Meta-Object Protocol: allows key VM instructions to be extended by the user.

Undo: transactional state changes can be undone.

Another key feature of XMF is the ability to extend the core language with syntax classes. A Syntax class has a grammar that describes how to process the concrete form of the new language construct and how to produce a replacement abstract syntax structure. The grammar language and parsing machinery are all written in XMF.

XMF is a Java program and can be downloaded by following this link. Instructions for starting XMF are given here under Software -> XMF. There are many language constructs included in XMF including: loops; classes; XML processors; code generators; micro-Java; rule-based languages; data walkers; HTML generation; pretty printers. XMF classes allow new definitions to be added dynamically and therefore system classes can be extended.

XModeler

XModeler is a tool for executable modeling. It is build on top of XMF by adding language constructs for controlling GEF libraries on Eclipse. It can be used as an IDE for developing XMF programs and for graphical modeling. Since it provides access to graphical primitives it allows graphical modeling languages to be developed in a number of ways, for example meta-packages are a lightweight way of producing a tailored language.

A simple example of the use of XModeler to develop and view an XMF application is given here (together with an extended version of this note). The application shows how a simple language can be developed for checking snapshots of the library model shown in XMF and XModeler below: