comparing language workbenches - gamlor

18
Comparing Language Workbenches Roman Stoffel University of Applied Sciences Rapperswil (HSR), Switzerland MSE-seminar: Program Analysis and Transformation December 23, 2010 Abstract To create a domain specific language basic tools like the parser, compiler or interpreted have to implemented. Additionally a integrated development environment (IDE) for a language is expected today. Therefore tools which allow you to define and implement domain specific languages including the IDE start to show up. In this paper three different approaches to tackle these challenges are introduces and compared. 1 Introduction Domain specific languages (DSL) have been around for ages. Recently creating and using DSLs has become popular again. Embedded DSLs, also known as internal DSL, are writ- ten in a host language. They cleverly use con- structs of the host language to create the DSL. External DSLs are not embedded in an exist- ing language. They are separate languages which bring with their own syntax and tool- chain. In this paper I take a look at tools to create external DSLs. There have been tools for creating exter- nal DSLs for decades. However, this is not enough. Today developers expect more than just a raw compiler or interpreter. They ex- pect a integrated development environment (IDE) with error checking, code completion, refactoring support and more assisting func- tionality. This is where language workbenches come into the picture. Language workbenches [20] allow you to create and modify DSLs and also directly use them. It assists you with cre- ating a full-fledged IDE for the created DSLs. In this paper I’m going to compare two lan- guage workbenches which follow different ap- proaches to tackle the problem and a tool for domain driven code generation. 2 Criteria For Language Workbenches In order to compare the different tools, I lay out some basic criteria for a language work- bench. It is a collection of features and capa- bilities which I expect from a development en- vironment and functionality which is required to create DSLs. Integration with other tools : Programming tools are rarely used standalone and in iso- lation. Usually a whole collection of tools is used for different purposes. This means that a language workbench should work to- gether with other tools. The most impor- tant and widely used tools are version control systems, build systems and testing environ- ment. Therefore, I’m going to compare how the different language workbenches work to- gether with these three categories of tools. Creating DSLs : An important feature is 1

Upload: others

Post on 12-Feb-2022

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Comparing Language Workbenches - Gamlor

Comparing Language Workbenches

Roman StoffelUniversity of Applied Sciences Rapperswil (HSR), Switzerland

MSE-seminar: Program Analysis and Transformation

December 23, 2010

Abstract

To create a domain specific language basic tools like the parser, compiler or interpretedhave to implemented. Additionally a integrated development environment (IDE) for alanguage is expected today. Therefore tools which allow you to define and implementdomain specific languages including the IDE start to show up. In this paper three differentapproaches to tackle these challenges are introduces and compared.

1 Introduction

Domain specific languages (DSL) have beenaround for ages. Recently creating and usingDSLs has become popular again. EmbeddedDSLs, also known as internal DSL, are writ-ten in a host language. They cleverly use con-structs of the host language to create the DSL.External DSLs are not embedded in an exist-ing language. They are separate languageswhich bring with their own syntax and tool-chain. In this paper I take a look at tools tocreate external DSLs.

There have been tools for creating exter-nal DSLs for decades. However, this is notenough. Today developers expect more thanjust a raw compiler or interpreter. They ex-pect a integrated development environment(IDE) with error checking, code completion,refactoring support and more assisting func-tionality. This is where language workbenchescome into the picture. Language workbenches[20] allow you to create and modify DSLs andalso directly use them. It assists you with cre-ating a full-fledged IDE for the created DSLs.In this paper I’m going to compare two lan-

guage workbenches which follow different ap-proaches to tackle the problem and a tool fordomain driven code generation.

2 Criteria For LanguageWorkbenches

In order to compare the different tools, I layout some basic criteria for a language work-bench. It is a collection of features and capa-bilities which I expect from a development en-vironment and functionality which is requiredto create DSLs.

Integration with other tools: Programmingtools are rarely used standalone and in iso-lation. Usually a whole collection of toolsis used for different purposes. This meansthat a language workbench should work to-gether with other tools. The most impor-tant and widely used tools are version controlsystems, build systems and testing environ-ment. Therefore, I’m going to compare howthe different language workbenches work to-gether with these three categories of tools.

Creating DSLs: An important feature is

1

Page 2: Comparing Language Workbenches - Gamlor

support for creating DSLs. There are differ-ent aspects to it. You need to be able to de-fine the grammar and the semantic meaning ofyour DSL. In order execute your DSL a trans-formation to the language or runtime systemis required. Can the tool deal with complexgrammars? Are there possibilities to debugthe transformation from the source DSL tothe target language?

IDE assistance: A modern IDE likeEclipse, IntelliJ IDEA or Visual Studiohas tons of features like syntax highlight-ing, error detection, debugging-support, code-navigation, auto completion and refactoring.It also provides means to discover the lan-guage and API of libraries by showing the ap-propriate documentation and improvements-suggestions. In a language workbench this iseven more important. These features shouldbe available for the language workbench itselfand for the created language. It should as-sist the developer with implementing a DSLand should also provide means and tools forimplementing IDE support for a DSL.

Combination of DSLs: The central idea ofLOP is to have languages which fit the prob-lem domain. But usually software has differ-ent concerns and it’s a good practice to sep-arate these concerns. For LOP this meansthat we have different DSLs for the differentconcerns. As soon as we have multiple littlelanguages we want to combine them. So thelanguage workbench should provide means tocombine different existing languages.

Changing DSLs: In modern software de-velopment refactoring is a regularly used prac-tice to improve the code quality and keep asystem ready for future changes. We’ve alsoseen that general purpose languages evolveto adopt the changing environment Favre [7].However, you it is very hard to change thesyntax or behavior of existing language con-structs in a language, since that almost cer-tainly breaks existing programs. You only canadd new features to to the language. In in aLOP environment the development team has

tight control over the used languages. Thismeans that we should have two capabilities.The first is to refactor existing code written inthe DSL. The second capability is to changethe DSL itself. For example to change theDSL syntax and not break existing code andstill keep the semantic meaning of the lan-guage.

3 The Tools

In this section I present three tools and givean overview of their functionality.

3.1 Meta Programming SystemMPS

In 2009 Jetbrains, known for their IDEs likeIntelliJ IDEA, RubyMine or Resharper, re-leased their approach to LOP called MetaProgramming System (MPS) [10]. The ideafor MPS was introduced by Sergey Dmitriev[24] and is heavily influenced by the Inten-tional Programming approach [3].

The goal of MPS is to provide an environ-ment where you develop and evolve your DSLalong with your application. It is not built tocreate a new language which is then shippedto a third party.

3.1.1 Programs as Models

What makes MPS quite unique is that itstores the programs an object model insteadof text. In MPS the storage and the visualrepresentation of a program is separated. Thisis different to regular programming languageswhere the storage and visual representation isthe same, namely text. First of all we needto understand the motivation behind this ap-proach. This different take on programmingtries to avoid the inherent limitations of a textbased solution.

In a text-based programming language agreat effort is required to parse the source-code. A precise grammar needs to be defined

2

Page 3: Comparing Language Workbenches - Gamlor

to describe the language. With this the textis parsed to an abstract syntax tree (AST)which then is processed further. While lots oftools assist you to define a grammar and cre-ate parser it is still not an easy task. Defin-ing an grammar is difficult and gets harder asthe language evolves. You always have to en-sure that new language constructs don’t makethe grammar ambiguous. Also creating a ro-bust parser is challenging. A parser shouldbe able to provide meaningful error messages.And for IDE support a parser should be ableto deal with incomplete and invalid programs[18]. This is still not enough. Today therefactoring support of IDEs is getting moreand more sophisticated. Often refactoringsdo their transformation on the AST. How-ever, since the program is written in text thistransformation have to be translated back totext and should preserve the layout of the text[22, 14].

Now in MPS programs are persisted as amodel and not as text. This avoids all theissues related to parsing and working withtext. Let’s explore this approach with exam-ples. Let’s say we have an object orientedlanguage in MPS. How does such a modellook like? Well in an object oriented lan-guage there are constructs like classes, meth-ods, fields, method-calls, program-statementsetc. In MPS such constructs are called con-cept. Let’s say we’ve a car-class. Then an in-stance of the class-concept, which contains in-stances of method-concept instance, is stored.Now we can start to imagine how programsare stored. In MPS we don’t create gram-mars; instead we create a meta-model of ourlanguage model, hence the name Meta Pro-gramming System. This means to define alanguage we create concepts such as a class-concept, method-concepts etc. We also de-scribe the relations between the different con-cepts like that a class consists of methods andfields. The layering of software in a base leveland a meta level is also known as reflectionpattern[5] and pursued by model driven ap-

proaches [8].

Program

Meta-Model

Car:Class

Start:Method

Drive:Method

Start() : MethodCall

Class-Concept

Instance of

Method-Concept*

1

Instance of

SpeedUp():MethodCall

MethodCall-Concept*

1

Instance of

Figure 1: Programs as model

But how can we now write and use thedescribed language? For this we need somekind visualization or editor. That’s exactlywhat you create in MPS. You create one ormultiple editors which operate on the modelrepresentation of your programs. An editorcan be a spread-sheet, a UML-editor, any-thing which can visualize and manipulate theprogram-model. Since MPS is focused on pro-gramming language the editor usually mimicsa text-editor.

All in all we end up with a very sophisti-cated program modeling system.

3.1.2 MPSs Collection of Languages

MPS brings a whole collection of languageswith it, which themselves are developed inMPS [12]. The basic language is called ‘BaseLanguage’ and is a MPS version of Java. Ad-ditionally MPS brings extensions to this Base

3

Page 4: Comparing Language Workbenches - Gamlor

Language for different aspects, like DSLs forcollections, tuples, closures etc. You can re-fer to those extensions in your project andthen use them. Besides the general purposeBase Language and extensions there are lotsof other DSLs. There are languages for defin-ing concepts, a language for describing edi-tors, a language for describing refactorings, alanguage for describing constrains on conceptsand so on. Those languages are used to createDSLs in MPS.

3.1.3 Model to Model Transforma-tions

The compilation process in MPS is a model tomodel transformation. Your DSL-models aretranslated into another model, typically intoa Base Language model. For this task MPSagain provides its own DSL.

As alternative you can transform a modelinto text, for example, if there’s no appropri-ate MPS language available. And MPS usesthe model to text transformation to transformits Base Language to Java, which then is com-piled and executed.

3.1.4 Talking To The Outside World

The DSLs you create have to talk to the out-side world via other languages and existinglibraries. We already have seen that we cantransform a model to text if necessary. But weprobably want to use libraries in MPS. Thismeans we need to be able to refer to artifactswhich live outside of the MPS world. To dothis so called ‘stubs’ are used [13]. Stubs area representation of artifacts outside of MPS,like existing API’s, frameworks etc. For ex-ample we in MPS we need stups to use theJava libraries like collections, net-work accessetc.

For stubs you first need a MPS repre-sentation of your target language / frame-work. Then you can define a stub-generatorin MPS, which transforms the external source-

code or API definition into MPS-stubs usingthe previously declared MPS concepts. To-gether with the right generators you can thentalk to the outside world.

A good example is MPS’s Base Language.This language is the door to the Java world.It models a language which is very close toJava. Furthermore there’s a model to texttransformation for the Base Language to gen-erate Java source code. The final piece is astub generator which creates stubs for Java-API’s. These stubs then allow you to call ex-isting Java libraries.

3.1.5 MPS by Example

Let’s take a look at a small example to illus-trate the basic concepts of MPS. We createa language to describe a data model. Thislanguage consists of simple type definitions,which have a type-name and a list of datafields. A data type which describes a personwith first- and surname should look somethinglike this:e n t i t y Person {

f i rstName : s t r i n gsirname : s t r i n g

}

In MPS we first describe a meta-model ofour DSL with MPS-concepts. In our smallDSL there are three main concepts. There’sthe ’entity’-concept which is an abstract datatype description with a name and fields. A fieldhas a name and a type. The last concept is atype, which can be a built-in type like stringand integer. Additionally a type can refer toan entity. Our model of the language is shownin figure 2. Now these relations are modeledin MPS using the Structure Language. Forthe entity concept we add a relation the fieldconcept and give it a name property. Becausea name is something very common there’s apredefined concept ’INamedConcept’. Thisbrings some predefined capabilities with it,like the renaming refactoring. Hence we in-herit from that concept to get those features.

4

Page 5: Comparing Language Workbenches - Gamlor

name

EntityConcept

name

FieldConcept

FieldType

StringType

IntType

*

1

*

1

EntityType1

1 < type of

Figure 2: Model of our DSL Figure 3: Concepts of our DSL

Figure 4: Defining an editor Figure 5: Using the editor

The figure 3 shows the concept declaration forthe entity.

After defining the concept we create edi-tors for all concepts, shown in figure 4. In ourDSL we need editors for our entity-concept,field-concept etc. These editors define howthe DSL is displayed and edited. The editoris described as a collection of cells. In eachcell has content, like lables, text-fields, morecells, lay outing components, cells which iter-ate over data etc. For each cell we can config-ure additional behavior and style in a separatewindow with a CSS-like language. For ourDSL we create an editor which first has some

label cells which contain with the ‘entity‘-text,followed by a cell which has a text-field for theentity name. After that we add a cell whichiterates over all fields of the entity model. Theresulting editor looks is shown in figure 5.

The final step is to create the transforma-tion of our DSL to the Base Language. Wedo this by writing an example of the desiredresult first. Then we annotate this result withmacros. There are macros like loops, condi-tionals, replacements etc. For our DSL westart by writing a simple Java bean in theBase Language. Then we start to annotatethe different parts of this prototype. We re-

5

Page 6: Comparing Language Workbenches - Gamlor

Figure 6: Translate to Base Language

place the class-name with a macro to use thename of the entity. We add a loop-macro totranslate fields into getters and setter and soon and so forth. In figure 6 you see the tem-plate with the macros on the left. On the rightis the behavior which we want to add to themacro.

3.2 Actifsource

Actifsource [1] is a tool to create complex do-main models and generate code out of them.It doesn’t allow you to create a new language,so it isn’t a really language workbench. There-fore it cannot directly be compared with otherlanguage workbenches. However, its modelbased approach shares some similarities MPS.In this paper we only take a brief look at Ac-tifsource.

3.2.1 Similarities to MPS

As in MPS you programs are captured in mod-els, which then are translated to a target lan-guage. You build a meta-model of your prob-lem domain. For example, when you build ameta-model of a web-service then you describethe building blocks like parameters, servicename, etc. Once the meta-model is built, youuse the building blocks to model your prob-

lem. This model then is translated to the tar-get language, like Java, C#, Ruby etc.

Activsource is a regular Eclipse plug-in.Therefore, it can be used together with allthe other features and plug-ins for the Eclipseplatform.

3.2.2 Differences to MPS

Now there is a big difference between MPSand Actifsource. In Actifsource you cannotbuild editors for your meta-model. Insteadyou use a UML [21]-like language to describethe meta-model and also the model of yourapplication. This means that you cannot cre-ate a complete new language, but rather aspecialization of the UML model. The limi-tations make Actifsource also much easier tolearn and use. You don’t need to create an ed-itor for your meta-model, which can be quitecomplex. On the other side it restricts you toproblems which can be modeled in UML.

The models in Actifsource are translatedto the text of the target language. For this aspecial template language is used.

3.2.3 Different Purpose

Actifsource has a different target audiencethan language workbenches. It’s a modeling

6

Page 7: Comparing Language Workbenches - Gamlor

Figure 7: DSL model in Actifsource

Figure 8: Translation template Figure 9: Model in Actifsource

tool, which allows you to model your problemswith UML. Such modeling tools can assist youin areas where there’s a lot of boiler plate codeand where modeling complex relationships isimportant. However it cannot compete in ar-eas where UML isn’t an appropriate language.

3.2.4 Actifsource by Example

We use the small language we used for theMPS example to illustrate the features of Act-ifsource. We start by implementing the modelshown in figure 2. The example implementa-tion is shown in figure 7.

After that we can define the transforma-tion from the model to Java source code. Forthis the template language is used. It pro-vides access to the model and can generatecode accordingly. We build a Java bean lineby line and access the model for the informa-tion. This way, we can use the entity-nameas class name, use the fields for getters andsetters and so on. In figure 8 you can see the

transformation template for our DSL.Now everything is ready. We can model

our entities with the UML dialect we’ve cre-ated. This model is then translated to regularJava code and ready to be used as shown infigure 9. Then our model is translated to Javasource code.

c l a s s AddressBean{p r i v a t e S t r i n g s t r e e t ;

p u b l i c void s e t S t r e e t ( S t r i n g value ){t h i s . s t r e e t = value ;

}

p u b l i c S t r i n g g e t S t r e e t ( ){re turn t h i s . s t r e e t ;

}

p r i v a t e S t r i n g c i t y ;

p u b l i c void s e t C i ty ( S t r i n g value ){t h i s . c i t y = value ;

}

p u b l i c S t r i n g getCity ( ){re turn t h i s . c i t y ;

}}

7

Page 8: Comparing Language Workbenches - Gamlor

3.3 Spoofax

The Spoofax language workbench [15] is basedon the popular Eclipse platform. In contrastto MPS it uses a classic text based approachfor DSLs. The Spoofax platform providestooling for defining grammars, transformingthe DSL to the target language and provid-ing IDE support for the DSL. You can editand develop the DSL in the same Eclipse in-stance, which results in very tight feed-backloop. To define the grammars the Syntax Def-inition Formalism (SDF) [9, 6] is used. Ontop of this the Stratego transformation lan-guage [19] is used to transform the DSL tothe target language. Additionally, there is aspecial editor language for defining syntax-highlighting, code-outline, code-folding andcode-completion.

The Spoofax language workbench takesadvantage of the Eclipse IDE Meta-toolingPlatform IMP. The final language can be ex-ported as regular Eclipse plug-in. This allowsyou to distribute the created language to otherpeople.

3.3.1 Syntax Definition Formalism

The SDF-language is a pure and declarativelanguage Heering et al. [6], Kats et al. [16].Like other grammar definition languages itdescribes productions rules of the grammar.But it doesn’t allow embedding any code orrules with side effects. The SDF-language isbacked by a scannerless generalized-LR parser(SGLR) [4]. Unlike other language categorieslike LL(k), LL(*) or LALR(k) SGLR supportsthe full range of context free grammars Katset al. [16], Visser [4]. This has a great advan-tage. Context free grammars are closed undercomposition. When you combine two contextfree grammars the result is still a context freegrammar. This isn’t the case when you onlyhave a subset of context-free grammars likewith LL(k), LL(*) or LALR(k). In practicethis means that it is possible to combine dif-

ferent grammars with SDF. You can importand reuse other existing grammars.

Now a context-free grammar may producean ambiguous parse-tree. In such cases theSGLR parser returns a parse-forest instead ofparse-tree. In such cases you can express asso-ciativity of productions and prioritize the pro-duction rules and try to make the grammarunambiguous. The fact that it SDF doesn’tforce this with a technical limitation makesthe process much easier a cleaner. The ruleswhich make a language unambiguous are not’hidden’, but are clearly stated with annota-tions.

3.3.2 Transformations as FundamentalConcept

Spoofax uses the Stratego [19] transformationlanguage to describe transformations fromthe source AST to the final target language.Stratego allows you to write reduction rulesthat describe transformation steps. Usuallysuch transformations consist of rules whichfirst remove the syntactic sugar from thesource language. For example, we transforma high-level foreach loop to a lower level con-structs like a while loop. Then other transfor-mation rules describe the transformation fromthe basic language constructs to the targetlanguage.

However, Spoofax uses this transforma-tion process not only for translating theDSL into the target language. Transforma-tions are a fundamental concept of Spoofax.Think about features like error-messages, typelookups or auto-completion. This can be de-scribed as special transformation of the sourcecode. For error messages the code is trans-formed to a list of errors. For type-referencesthe source-code is transformed to list of knowntypes. For auto-completion a list of possibletypes, fields and methods is generated fromthe source. This is the fundamental way howyou describe and provide complex IDE fea-tures in Spoofax.

8

Page 9: Comparing Language Workbenches - Gamlor

Only transformations to simple error listsis not enough. For compiler-error messagesand IDE features it is extremely vital thatthe location of the error is known. Spoofaxtakes care of this. Each node in the ASTis associated with the origin position in thesource code file. As transformations are ap-plied the position information is preserved.In the error-reporting transformation we justneed to return the right node to mark the er-ror location.

A Term Transport Layer: The Strategotransformation system has to consume theoutput of the parse subsystem. Spoofax usesefficient abstract data types, which are basedon annotated terms Van den Brand et al. [17],referred to as ATerms. A textual represen-tation of ATerms is also used to display theAST. However, it is possible to write adaptersin Java for other term representations.

3.3.3 Editor Language

Spoofax uses a special editor language do de-fine the features of the generated IDE. Inthis language you can define IDE featureslike syntax coloring, points where auto com-pletion is invoked, outline and code-foldingproperties. Here we can use the lists whichare created by transformations as informationsource. For example, auto-completion usesthe list of types which has been generated bya Stratego transformation.

3.3.4 Spoofax by Example

Again we use our small DSL from the previ-ous examples to show the basic concepts ofSpoofax. The first thing we do in Spoofaxis to write down the grammar. For our gram-mar we import the ’Common’ grammar whichcontains often used parser rules like white-space handling, numbers, identifiers etc. InSDF you write first then matching symbolsfollowed by the resulting symbol. In the curlybraces you can additional information, in ex-

ample the name of the AST node.module GamlorEntityLanguageimports Commonexport s

context−f r e e s t a r t −symbolsSta r t

context−f r e e syntax

EntityDef ∗ −> Star t { cons ( " E n t i t i e s " ) }" e n t i t y " ID " ( " F i e ld ∗ " ) "

−> EntityDef { cons ( " Entity " ) }ID " : " Type −> Fi e ld { cons ( " F i e l d " ) }ID −> Type { cons ( " Type " ) }

After creating the grammar we start tobuild the compilation process by creating atranslation to Java. We create rules whichtranslate each node of the generated AST toa piece of text. The AST-nodes of entities aretranslated to classes, the fields to getters andsetters. In the snippet below we take a ’Field’-AST node and replace it with the given text.Within some parts are replaces with variables.to−java : F i e ld (x , Type ( t ) ) −> $ [

p r i v a t e [ t ] [ x ] ;p u b l i c [ t ] get_ [ x ] {

re turn [ x ] ;}p u b l i c void set_ [ x ] ( [ t ] [ x ] ) {

t h i s . [ x ] = [ x ] ;}

]

The second step is to improve the IDEsupport for our DSL. Let’s take a look atthe error detection for our DSL. For exam-ple, we should check that a property uses atype which actually exists. For this, we cre-ate a list of known entities with the Strategotransformation language. Then we add a rulewhich checks that the type of a field is eitherbuilt in or one of the entities.// Create a l i s t o f known e n t i t i e srecord−e n t i t y :Ent ity (x , body ) −> Entity (x , body )with

// Create a lookup r u l er u l e s (

GetEntity :+ x −> x)

// Check that a f i e l d only uses known typestype−e r r o r :F i e ld (x , Type ( type ) )

−> ( type , $ [ Type [ type ] i s not d e f i n e d ] )where

not ( ! type => " S t r i n g " ) ;

9

Page 10: Comparing Language Workbenches - Gamlor

Figure 10: The IDE for our DSL

not ( ! type => " Int " ) ;not ( ! type => " Long " ) ;not(<GetEntity> type ) // lookup type

The list of known entities is used for fur-ther IDE features, like type-completion:

complet ions// Syntax complet ion :complet ion template

: "msg " <msg> ( blank )complet ion template

: " e n t i t y " <e> " {}" ( blank )

// Semantic ( i d e n t i f i e r ) complet ion :complet ion proposer

: ed i to r −completecomplet ion t r i g g e r : " : "

We can add further features to the IDE sup-port like syntax highlighting, code folding etc.The final result is a nice IDE for our language,as shown in figure 10. As last step we can ex-port our IDE features as Eclipse plug-in anduse the DSL for our projects.

4 ComparisonsAs discussed there are different approachesfor language workbenches. MPS and Spoofaxtackle DSL in a very different way. That’swhy it’s interesting to compare these two re-alizations and find out where their strengthsare. Because Actifsource is not a languageworkbench it is covered more briefly than theother two tools.

4.1 Integration With Other Tools

In this section compare how the three toolsare integrated with other tools.

4.1.1 Integration with Text BasedTools

Here MPS has serious short comings due to itsmodel-based nature. Text-based tools don’twork for MPS. MPS uses XML as storageformat, but the stored XML documents arevery technical and not ‘human’ readable. This

10

Page 11: Comparing Language Workbenches - Gamlor

means that the whole text-based tool chainprogrammers are used to doesn’t work withMPS. Diff and merge tools, text-editors andother text-tools only show the raw XML. MPSsupports popular version-control systems andbrings its own merge/change/diff-view whichshows the changes in the right format. As longas you use a version control system supportedby MPS the situation acceptable. But evenfor some more complex changes MPS onlyshows the underlying XML-storage instead ofthe regular MPS views. The issues go further.Even regular copy and paste functions don’twork. You cannot copy a code-snippet from atext-source like a tutorial into MPS. BecauseMPS cannot deal with text, it needs a com-plete model. This situation is a bit improvedin the upcoming MPS 2.0 [11].

The situation in Actifsource looks verysimilar to MPS. It stores its models in XML-files as well and brings its own diff tools forversion control systems. Since Actifsource isnot a replacement for regular programminglanguage, but rather a helpful addition thesituation is not as bad.

In Spoofax all text-based tools work justfine because it is all text based. For ver-sion control Spoofax even has a clear nam-ing scheme to distinguish generated files fromhand edited files. All files which have ’.gener-ated.’ in the name shouldn’t be checked in toa version contol system.

4.1.2 Integration with ContinuousBuild Tools

MPS provides a way to build the languagesand projects with Apache Ant. So it is pos-sible to build it with most continuous buildtools for Java. MPS actually brings its ownDSL to describe the build process. This isalso based on Ant but provides a nicer syn-tax. MPS creates a bootstrap Ant build-scriptwhich then calls into the scripts written in theDSL. However, the default generated buildscript contains hard references to the MPS-

system, which could be different on a build-server than on a developers machine

ctifsource also brings Apache Ant taskswith it. This allows you to run the Actifsourcemodel to code generator during the build.

Spoofax also uses Apache Ant as buildtool and a Spoofax project can be build onmost continuous build systems. Unlike MPSit doesn’t bring its any DSL to describe thebuild.

4.1.3 Unit-Testing

Once again MPS brings its own testing DSLwith it. This DSL is based on the popularJUnit testing framework. It contains specialsupport for instantiating parts of the modelunder tests. It allows you to use your DSLin the test-case ad write a small snippet inyour DSL. In the test you then get the model-instance where you can check if the model be-haves as expected. For example to test a mathDSL you write a snippet in the math DSL.Then you get the model instance in the testto perform tests on it.

Actifsource and Spoofax don’t have spe-cial support for testing. Of course you canuse the regular tooling like JUnit and Eclipseplug-ins to create test cases.

4.1.4 Integration with Environment

MPS doesn’t have any special integration withother tools. While it is based on the IntelliJIDEA platform it doesn’t provide any exportmechanism to that IDE. It can use some IDEAplug-ins, but by no means all IntelliJ IDEAplug-ins. Therefore MPS is pretty isolated.

In contrast Actifsource and Spoofax areregular Eclipse plug-ins and can be used to-gether with other plug-ins. Furthermore,Spoofax allows exporting the created lan-guages as stand-alone Eclipse plug-in.

11

Page 12: Comparing Language Workbenches - Gamlor

4.2 Creating DSLs

4.2.1 Defining Grammars and Com-plex Languages

Both, MPS and Spoofax, allow you to de-fine fairly complex languages. In Spoofax youcan create arbitrary context-free languages.In MPS you can create complex meta-modelsand editors to build languages.

Actifsource is not a language workbench,hence it cannot be compared with the othertwo tools.

4.2.2 Transformation

MPS, Actifsource and Spoofax use a trans-formation language to translate the sourceDSL to the target language. All three toolsuse a similar approach where you can writea template and then replace the right partsof the template according to the source ma-terial. Spoofax and Actifsource translate theoutput to text. MPS transforms DSL-modelsto another program-models, although modelto text transformations are also supported.

4.2.3 Debugging

MPS brings debugging support for its BaseLanguage and the extensions to that lan-guage. It is possible to extend the debuggingsupport for a DSL as long as it is based on theBase Language. However, for DSLs not inte-grated into the Base Language no debugger isavailable. You cannot even step through thefinal resulting Java code. For that you needto use an external IDE like Eclipse or IntelliJIDEA.

Actifsource doesn’t have a model debug-ger, but you can use the regular Eclipse de-bugger to debug the generated code.

Spoofax itself doesn’t bring any direct de-bugger support for generated DSLs. However,since it’s an Eclipse plug-in you can use theregular Eclipse debugger to debug the gener-ated code. And it is possible to use the under-

lying Eclipse infrastructure to implement thedebugger support separately.

4.3 IDE assistance

Let’s take a look at the IDE support of thethree tools.

4.3.1 Syntax Highlighting, Code Fold-ing

MPS and Spoofax provide good support toimplement syntax highlighting and code fold-ing. In MPS this is done by changing the styleof elements in the editor of a model. For thisa CSS-like language is used to define the styleof the different elements. In Spoofax you candefine syntax highlighting and code folding inthe editor language. By default, certain ele-ments like terminal symbols are already col-ored appropriate. You then can give colors ofother nodes-types in the AST.

Although Actifsource isn’t a languageworkbench it still brings limited support forsyntax highlighting. This is useful when youtranslate models into a certain programminglanguage. Then the syntax highlighting helpsto read the generated code.

4.3.2 Navigation & Discoverability

In MPS code-navigation works extremely wellfor the MPS languages and for created DSLs.MPS always knows to what you’re referringto in your language. You don’t need to doany additional work. This way you can nav-igate along definitions of any symbols, typesetc. You can also find all locations where asymbol is used. Additionally you always canopen up the concept of the current elementto find out how something is defined. This isalso useful to learn MPS itself, since you cantake a look at the implementation of the MPSlanguages.

Actifsource brings also excellent supportfor navigating along the models. You can find

12

Page 13: Comparing Language Workbenches - Gamlor

the definitions, references, subtypes etc. forany artifact in the model.

In Spoofax code navigation and discov-erability are very different for the Spoofaxlanguages, SDF and Stratego, and DSLsyou create yourself. For the Spoofax lan-guages there are limited navigation featuresavailable. You can navigate to the defini-tion of transformation-rules and grammar-productions. But advanced navigation fea-tures like finding all usage locations of a sym-bols are not supported. For such cases youare stuck with text-searching for symbols anddefinitions across the different code artifacts.For the DSL you easily can define look-up ta-bles for symbols and add provide navigationsupport, although some work is required toadd this features for your DSL.

4.3.3 Error-Detection

In MPS typical errors are prohibited by themodel approach. You cannot enter DSL codenot defined by the model. Additionally, youcan define constrains on the model that arevalidated at runtime. For complex error de-tection you can add type-system definitionswhere you can manually program validationsof the models.

Actifsource also catches most errors be-cause you cannot write anything which isn’tdefined by the meta-model. Besides that youcan add additional validation rules, written inJava.

In Spoofax there are two types of errordetection. All syntactic errors are checked bySpoofax and marked in the IDE. For semanticerrors you need to define transformation ruleswhich return the appropriate errors.

4.3.4 Auto-Completion

Again MPS benefits from its model based pro-gramming that it automatically can infer alot of information and bring the appropriateauto-completion suggestions. Also constrains

on the model are honored in the suggestions.To polish the editor you can define ‘inten-tions’ to your model. Intentions are sugges-tions, transformations, refactorings, etc, ap-propriate for current code.

The same applies to Actifsource auto-completion; it can give you useful suggestiondue to the model restrictions. You can refinethe auto completion with additional rules.

Like before, in Spoofax you use Stratego totransform the AST to look-up tables. Theselookup tables are then used to provide appro-priate auto completion at the right locations.

4.3.5 Refactoring Support

In MPS basic refactorings like renaming, moveand safe deletion are implemented automat-ically. For MPS languages more advancedrefactorings are available. Additional refac-torings for your DSL can be defined with aspecial refactoring language to describe thetransformations on the model.

Actifsoure brings some basic refactoringslike renaming with it. However you cannotcreate more complex refactorings yourself.

At the moment Spoofax doesn’t provideany direct support for refactoring. TheSpoofax team hopes that refactorings can bedescribed declaratively in the future [15]. Butit isn’t implement right now. Of course, youcan fall back to the Eclipse platform to imple-ment refactorings for your DSL in Java withthe Eclipse APIs.

4.4 Combination of DSLs

MPS strongly encourages to create manysmall DSLs and the combine and reuse DSLs.For example, MPS provides a collection ofextensions to the Base Language which canbe optionally included. Also all MPS specificlanguages like those for concepts, constrains,tranformations often resue parts of the samelanguage.

To support this kind of combination of

13

Page 14: Comparing Language Workbenches - Gamlor

DSLs MPS strongly relies on the fact that ev-erything is described with MPS concepts andthat there’s no parsing required. It also relieson the fact that transformations are usuallymodel to model transformations which end upin a Base Language model. If the differentDSL are translated to different models, let’ssay to Java and Javascript, then the combina-tions of DSL is not possible without redefiningone of the transformations.

Actifsource also allows you to refer to ex-isting models and reuse parts of it, similar toMPS.

In Spoofax allows you to use multiple DSLside by side. You can create two separatesDSLs and the export them as Eclipse plug-in. Then you can install both plug-in anduse both languages in your project. Also theSDF language is modular which makes it pos-sible to reuse syntax definition Kats et al. [16].However, I didn’t find a mechanism to importor refer to existing DSLs and reuse their im-plementation. I also belief that it’s hard tocombine and reuse the transformation and theeditor definitions.

4.5 Changing the DSL

In MPS you can freely change the representa-tion of the DSL, without destroying existingcode base. This is possible because in this caseyou only change the visual representation ofthe language but not the semantic meaningof it. Some simple refactorings like movinga property of a concept to a parent conceptalso work without breaking existing code. Butmore complex changes will break existing pro-grams.

Actifsource doesn’t support major meta-model changes. When you change the meta-model you may break DSLs.

In Spoofax there is no refactoring avail-able. Like other text-based DSLs it’s hardtochange the syntax or semantic meaning of thelanguage without breaking the existing code.

4.6 Overview & Recommendations

The overview of the strengths and weaknessesof the three compared tools are listed in table1.

Also I want to close with recommendationsto pick the right tool for the right job.

MPS is a great tool when you want tocreate a collection of DSLs, which then arecombined to implement a complex system.Additionally the DSL code should live rela-tively isolated from the rest of the system, be-cause it only can be edited in MPS. In suchcases MPSs excellent support for complex lan-guages and IDE support can unleash the fullpower of MPS. Where MPS is not usable is inscenarios where you develop a DSL and thendistribute it as plug-in/system to the devel-opers. MPS is a model based island, whichis hard to combine with other text based sys-tems.

Actifsource is great tool when you need tomodel complex systems and UML is an ap-propriate model language. In such cases itis a great addition that works together withother programming languages.

Spoofaxs strength is to build text basedDSLs for Eclipse. These DSLs then can beused together with general purpose languagesin the same project. Spoofax is also optimalwhen you want to distribute your DSL in formof an Eclipse plug-in.

5 Related Work

There have already been comparisons of lan-guage factories by Tony Clark and LaurenceTratt [25]. They focused on a broader spec-trum of ways to create DSLs, particularlanguages which encourage building internalDSLs.

Another comparison of different languageworkbenches was made by Bernhard Merkle[2], who analyzed a broad spectrum of tools.

It is also worth to mention that currentlya language workbench competition [23] is pre-

14

Page 15: Comparing Language Workbenches - Gamlor

MPS Spoofax ActifsourceIntegration With Text Based Tools – + 0Integration With Continious Build Tools 0 0 0Unit-Testing + 0 0Integration With Environment - ++ ++Defining Grammars And Complex Languages ++ ++ N/ATransformation ++ ++ +Debugging + 0 0Syntax Highlighning, Code Folding ++ ++ N/ANavigation & Discoverability ++ 0 +Error-Detection ++ + +Auto-Completion ++ + ++Refactoring Support + 0 0Combination of DSLs ++ + N/ARefactoring the DSL + 0 N/A

N/A Actifsource is not a language workbench, therefore it can only be compared partially

++ Excellent support for area/features

+ Good support for this area/features

0 No particular support for this area/features

- Bad support for this area/features

– Very bad support for this eare/features

Table 1: Strengh and Weaknesses of Spoofax, MPS and Actifsource

pared for the Code Generation 2011 confer-ence. There, different language workbenchesprovide a implementation of the same task.The goal is to be able to compare strengthsand weaknesses.

6 Conclusions

In this paper I’ve compared three differentlanguage workbench implementations, MPSand Actifsource which are model-based andSpoofax which creates regular textual lan-guages. All tree solutions provide a conve-nient way to define and implement a DSL to-gehter with IDE support.

MPS gains from its model-based approachsuperior IDE support, but it suffers heav-

ily that it cannot integrate to the text-basedmainstream tooling. If you can live with a rel-atively isolated system which provides greatIDE support for your DSLs you should take alook at MPS.

Actifsource is a tool which can help mod-eling complex systems with UML models.

Spoofaxs traditional approach integrateswell with other text-based tools and benefitsfrom the Eclipse platform. However it cur-rently cannot provide the same level of IDEsupport for its own DSL and the user definedDSLs. If you’re interested in creating DSLsand want to take advantage of existing tech-nologies the more pragmatic text based ap-proach is probably a better solution. Take alook at Spoofax or similar tools.

.

15

Page 16: Comparing Language Workbenches - Gamlor

References[1] actifsource GmbH [2010], ‘Actifsource’.

URL: http://www.actifsource.com/ (accessed 15th December 2010)

[2] Bernhard Merkle [2010], Textual modeling tools: overview and comparison of languageworkbenches, in ‘Proceedings of the ACM international conference companion on Objectoriented programming systems languages and applications companion’, SPLASH ’10,ACM, New York, NY, USA, pp. 139–148.URL: http://doi.acm.org/10.1145/1869542.1869564

[3] Charles Simonyi [1995], ‘The death of computer languages,the birth of intentional pro-gramming’.URL: ftp://ftp.research.microsoft.com/pub/tr/tr-95-52.doc

[4] E. Visser [1997], Scannerless generalized-lr parsing, Technical report.URL: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.37.7828

[5] Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad and Michael Stal[1996], Pattern-Oriented Software Architecture Volume 1: A System of Patterns, 1 edn,Wiley.URL: http://www.worldcat.org/isbn/0471958697

[6] J. Heering, P. R. H. Hendriks, P. Klint and J. Rekers [1989], ‘The syntax definitionformalism sdf, reference manual’, SIGPLAN Not. 24, 43–75.URL: http://doi.acm.org/10.1145/71605.71607

[7] J.-M. Favre [2005], Languages evolve too! changing the software time scale, in ‘Principlesof Software Evolution, Eighth International Workshop on’, pp. 33 – 42.URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=01572304

[8] Jean Bézivin [2007], On the Unification Power of Models, in ‘Software and SystemModeling’.URL: http://www.sciences.univ-nantes.fr/lina/atl/www/papers/OnTheUnificationPowerOfModels.pdf

[9] Jeroen Scheerder Joost Visser [2000], ‘A quick introduction to sdf’.URL: ftp://ftp.stratego-language.org/pub/stratego/docs/sdfintro.pdf

[10] JetBrains [2010a], ‘Jetbrains MPS’.URL: http://www.jetbrains.com/mps (accessed 20th November 2010)

[11] JetBrains [2010b], ‘Jetbrains MPS 2.0 M1 new features’.URL: http://confluence.jetbrains.net/display/MPS/What’s+new+in+MPS+2.0+M1(accessed 20th October 2010)

[12] JetBrains [2010c], ‘MPS 1.5 user guide, section platform languages’.URL: http://confluence.jetbrains.net/display/MPSD1/MPS+User’s+Guide (accessed27th November 2010)

16

Page 17: Comparing Language Workbenches - Gamlor

[13] JetBrains [2010d], ‘MPS user guide, stubs’.URL: http://confluence.jetbrains.net/display/MPSD1/Stubs (accessed 27th November2010)

[14] Kristoffer Norling Mikael Blom Peter Fritzson Adrian Pop [2008], ‘Comment- andindentation preserving refactoring and unparsing for modelica’.URL: https://www.modelica.org/events/modelica2008/Proceedings/sessions/session6a3.pdf

[15] Lennart C. L. Kats and Eelco Visser [2010], The Spoofax language workbench. Rules fordeclarative specification of languages and IDEs, in M. Rinard, ed., ‘Proceedings of the25th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems,Languages, and Applications, OOPSLA 2010, October 17-21, 2010, Reno, NV, USA’,pp. 444–463.URL: http://researchr.org/publication/KatsVisser2010

[16] Lennart C. L. Kats, Eelco Visser and Guido Wachsmuth [2010], Pure and declarativesyntax definition: Paradise lost and regained, in ‘Proceedings of Onward! 2010’, ACM.URL: http://www.lclnet.nl/publications/pure-and-declarative-syntax-definition.pdf

[17] M. G. T. Van den Brand, H. A. de Jong, P. Klint and P. A. Olivier [2000], ‘Efficientannotated terms’, Softw. Pract. Exper. 30, 259–291.URL: http://portal.acm.org/citation.cfm?id=343460.343468

[18] Maartje de Jonge, Emma Nilsson-Nyman, Lennart C. L. Kats and Eelco Visser [2009],Natural and flexible error recovery for generated parsers, in M. G. J. van den Brand andJ. Gray, eds, ‘Software Language Engineering (SLE 2009)’, Lecture Notes in ComputerScience, Springer, Heidelberg.URL: http://swerl.tudelft.nl/twiki/pub/Main/TechnicalReports/TUD-SERG-2009-024.pdf

[19] Martin Bravenboer, Karl Trygve Kalleberg, Rob Vermaas and Eelco Visser [2008],‘Stratego/XT 0.17. A language and toolset for program transformation’, Science ofComputer Programming 72(1-2), 52–70. Special issue on experimental software andtoolkits.URL: http://swerl.tudelft.nl/twiki/pub/Main/TechnicalReports/TUD-SERG-2008-011.pdf

[20] Martin Fowler [2005], ‘Language workbenches: The killer-app for domain specific lan-guages?’.URL: http://www.martinfowler.com/articles/languageWorkbench.html (accessed 22thDecember 2010)

[21] OMG [2010], ‘Uml specification’.URL: http://www.omg.org/spec/UML/ (accessed 15th December 2010)

[22] Peter Sommerlad, Guido Zgraggen, Thomas Corbat and Lukas Felber [2008], Retainingcomments when refactoring code, in ‘Companion to the 23rd ACM SIGPLAN conferenceon Object-oriented programming systems languages and applications’, OOPSLA Com-panion ’08, ACM, New York, NY, USA, pp. 653–662.URL: http://doi.acm.org/10.1145/1449814.1449817

17

Page 18: Comparing Language Workbenches - Gamlor

[23] S. Kelly A. Hulshout J. Warmer P. J. Molina B. Merkle K. Thoms M. Völter E.Visser[2010], ‘Language workbench competition 2011’.URL: http://www.languageworkbenches.net/ (accessed 16th December 2010)

[24] Sergey Dmitriev [2004], ‘Language oriented programming: The next programmingparadigm’.URL: http: // www. jetbrains. com/ mps/ docs/ Language_ Oriented_ Programming.pdf

[25] Tony Clark and Laurence Tratt [2009], Language factories, in ‘Proceeding of the 24thACM SIGPLAN conference companion on Object oriented programming systems lan-guages and applications’, OOPSLA ’09, ACM, New York, NY, USA, pp. 949–955.URL: http://doi.acm.org/10.1145/1639950.1640062

18