Montag, 11. Juni 2007

Easy Language Interpreters

In a recently published tutorial, we demonstrate a new way of defining an operational semantics and therefore automatically create an interpreter for meta-model based languages. The tutorial models a composite state automaton language including a simulator for such automatons. This article provides a motivation and overview about the presented method.

How complicated has it to be to create an interpreter for a language? An interpreter simply realizes the operational semantics of a language and allows to execute models or programs in that language. There are a lot of methods tailored for a mathematical precise semantics definition, and some of them, for example ASMs, even allow to automatically derive an interpreter from a semantics description. But in the end these methods are suited for language understanding. They can, for example, be used to proof properties like static safety. But methods like this are usually to cumbersome to be efficient. Hence, they are debilitating the design process of a language. When you want to try new language features, test for the user acceptance of a new behavior, or simply need a language tool fast, formal methods are a burden and not help.

We propose a technique that allows you to derive a language interpreter quickly: without learning a new formalism or new methodology. We simply take existing modeling techniques and combine them towards a new application: defining the operational semantics of a language. We start with regular meta-modeling, for example with MOF. We use A MOF 2.0 for Java to do this. When you have a meta-model for a language, you can create operations within this meta-model. These operations declaration will act as the interface to the language behavior. The implementations of operations, can modify a model. Operation implementations can apply simple actions like creating an element, set a value to an attribute, etc. When executed, each operation therefore leads to a sequence of model changes. Of course, operations can call other operations and one operation as to act as the main operation.

Viewed from this operations and implementations perspective, a model is simply an object-oriented program. From the semantics perspective we have defined a meta-model for possible system states (the MOF meta-model) and the operations and implementations define a sequence of transitions (model changes lead to a sequence of models). This is analog to the classical structural operational semantics definition as introduced by Plotkin in the early 80s.

How can you implement the operations in a meta-model. You can, of course, simply provide Java implementations. Ifyou want to use a more abstract behavior description, we provide another method based on UML Activities and OCL. We propose an UML Activitiy like language that uses predefined actions (create, set, delete, call another operation, etc.) as atomic activities. Control flow in this language is created with OCL expressions, and the actions can be parameterized with OCL expressions. The activity language can deal with operation parameters and return values.

With both implementation methods, Java and activities, you have a choice. Activities provide the higher abstraction level and are more readable. Java implementations perform better when executed and allow to use other Java APIs. With Java implementations you are not restricted to model actions. You can therefore create semantics that are connected to underlying platform. This makes it easier to integrate your language and models with your target platform. You can also mix the use of activities and Java and implement one operation with Java and another with activities.

What do you gain compared to other methods. Traditional mathematical methods are to cumbersome to be effective in the language design process. Other meta-model based approaches require you to learn a new action language. We only use existing languages and methodologies. If you know meta-modeling, object-orientation, activities, OCL, and Java, you can immediately start to create language and interpreter. The use of meta-modeling, especially with the CMOF model, allows very flexible and reusable language definitions. It even allows a pattern approach for languages. The system state is a model (instance of your meta-model) and you can apply other modeling techniques to the system state: invariants and conditions, model transformations, model based tests, or XMI based persistence. We provide a pragmatic way to model operational semantics and create language interpreters. Its an ideal complement to technologies language GMF, openArchitectureWare, and other language workbenches.

If you want to learn more, try our tutorial and this paper on our method.

1 Kommentar:

Anonym hat gesagt…

Hello everyone.

My name is Jonathan, currently based in belgium,
I am both English and French native language,
just wanted to say hello and Looking forward to sharing information with all of you:-)