
Xbase: Implementing Domain-Specific Languages for Java∗ Sven Efftinge Moritz Eysholdt Jan Köhnlein itemis AG itemis AG itemis AG D-24143 Kiel, Germany D-24143 Kiel, Germany D-24143 Kiel, Germany [email protected] [email protected] [email protected] Sebastian Zarnekow Wilhelm Hasselbring itemis AG Software Engineering Group D-24143 Kiel, Germany University of Kiel, Germany sebastian.zarnekow@ [email protected] itemis.de kiel.de Robert von Massow Michael Hanus Software Engineering Group Programming Languages and University of Kiel, Germany Compiler Construction Group [email protected] University of Kiel, Germany kiel.de [email protected] kiel.de ABSTRACT by the implementation of the programming language Xtend. Xtext is an open-source framework for implementing exter- Xtend is a functional and object-oriented general purpose nal, textual domain-specific languages (DSLs). So far, most language for the Java Virtual Machine (JVM). It is built on DSLs implemented with Xtext and similar tools focus on top of Xbase which is the reusable expression language that structural aspects such as service specifications and entities. is the foundation of Xtend. Because behavioral aspects are significantly more compli- cated to implement, they are often delegated to general- Categories and Subject Descriptors purpose programming languages. This approach introduces D.2.11 [Software Engineering]: Software Architectures| complex integration patterns and the DSL's high level of Domain-specific architectures; D.2.13 [Software Engineer- abstraction is compromised. ing]: Reusable Software|Reusable libraries; D.3.3 [Pro- We present Xbase as part of Xtext, an expression language gramming Languages]: Language Constructs and Fea- that can be reused via language inheritance in any DSL im- tures|Classes and objects; D.3.3 [Programming Langua- plementation based on Xtext. Xbase expressions provide ges]: Language Constructs and Features|Inheritance; D.3.3 both control structures and program expressions in a uni- [Programming Languages]: Processors|Code generation form way. Xbase is statically typed and tightly integrated with the Java type system. Languages extending Xbase in- herit the syntax of a Java-like expression language as well as General Terms language infrastructure components, including a parser, an Design, Languages unparser, a linker, a compiler and an interpreter. Further- more, the framework provides integration into the Eclipse Keywords IDE including debug and refactoring support. The application of Xbase is presented by means of a do- Domain-specific languages, Object-oriented programming, main model language which serves as a tutorial example and Language inheritance ∗This work is supported by the German Federal Ministry 1. INTRODUCTION of Education and Research (BMBF) under grant number The simplicity and application-specific syntax of DSLs in- 01S10008 creases the readability as well as the density of information. Hence, developers using DSLs cannot only develop systems faster but also understand, evolve, and extend existing sys- tems easier. There are two different but converging approaches for de- signing DSLs. On the one hand, there are the so called exter- nal DSLs [7]. An external DSL is a completely independent language built from scratch, such as the AWK1 program- ming language for file processing or the MENGES language 1 . http://www.gnu.org/software/gawk/ for programming railway control centers [9]. As external inconvenient and error prone to write, read and maintain DSLs are independent from any other language, they need information which closely belongs together in two different their own infrastructures like parsers, linkers, compilers or places, abstraction levels and languages. Additionally, the interpreters. More popular examples for external DSLs are techniques used to add the missing behavioral information SQL [2] or the Extended Backus-Naur Form (EBNF) [22] impose significant additional complexity to the system. So to easily interact with relational databases or representing far, for most projects, it seems more attractive to apply these formal grammars, respectively. workarounds than to implement an expression language from On the other hand, an internal DSL (sometimes also called scratch. embedded DSL) leverages a so called host language to solve The novel contribution of this paper is Xbase. It is a domain-specific problems. This idea originates from the reusable expression language which can be used in any Xtext LISP programming language, where several internal DSLs language. It comes with a complete grammar for a modern have been designed [10]. Examples of modern internal DSLs Java-like expression language as well as all the required in- are the OpenGL API, the Java Concurrency API, or the frastructure: Scala parser combinators. An internal DSL is basically an API which pushes the host language's capabilities to make • A parser and a lexer creating a strongly typed abstract client code as dense and readable as possible. syntax tree (AST). As internal DSLs are defined on top of a general pur- • A compiler translating the AST to Java source code, or pose programming language, their syntax is constrained to alternatively an interpreter running on the Java virtual what the host language allows. The advantage is that no machine (JVM). new language infrastructure needs to be built, because the parser and compiler (resp. interpreter) of the host language • A type system model, designed after Java's type sys- is used. Also it is possible to call out to and reuse the con- tem and supporting all Java 5 concepts, including gener- cepts of the host language, such as expressions. The down- ics. side is the limited flexibility, because internal DSLs have to be expressed using concepts of the host language. Also, in- • A linker that is implemented according to the Java ternal DSLs typically do not have special IDE support or scoping rules and binds against concept of the Java domain-specific compiler checks. type system. A domain-specific language (DSL) as we understand the • Advanced editor features, such as content assist, syn- term is a programming language or specification language tax coloring, code folding and error highlighting. dedicated to a particular problem or solution domain. Other definitions focus on the aspect that a DSL is explicitly not • Integration with Eclipse, such as call hierarchy view, intended to be able to solve problems outside of that par- type hierarchy view and other useful navigation fea- ticular domain [7], but from our viewpoint this is not an tures. important distinction. Creating a DSL and tools to support it can be worthwhile • A debugger allowing one to alternatively step through if the language allows one to express a particular type of the DSL or through the generated Java source. problem or solution more clearly than an existing language. Reusing Xbase in a language can be done by defining two ar- Furthermore, the kind of problem addressed by the DSL tifacts: A grammar that extends the provided Xbase gram- should appear frequently|otherwise it may not be worth mar and a Java type inferrer that maps the DSL concepts the effort to develop a new language. to the Java type model. Xtext2 is a framework for external textual DSLs. Devel- We first describe language development with Xtext in Sec- oping textual DSLs has become straightforward with Xtext tion 2. Section 3 introduces the Xbase language by giving because the framework provides a universal architecture for an overview on design goals and some examples for Xbase language implementations and well-defined default services. expressions. Two applications of Xbase are presented in Sec- Structural languages which introduce new coarse-grained tion 4. In Section 5, we take a look at some other work in this concepts, such as services, entities, value objects or state- field and relate it to Xbase. Finally, we draw our conclusions machines can be developed with very little effort. However, and give an outlook on some future work in Section 6. software systems do not only consist of structures. At some point a system needs to have some behavior which is usu- ally specified using statements and expressions. Expressions 2. THE XTEXT FRAMEWORK are the heart of every programming language and their im- Xtext is an extensible language development framework plementation is error prone. On the other hand, expressions covering all aspects of language infrastructure such as parsers, are well understood and many programming languages share linkers, compilers, interpreters and full-blown IDE support a common set and understanding of expressions. Unfortu- based on Eclipse. It is successfully used in academia as well nately, implementing a language with support for statically as in industrial applications. Among the industrial users typed expressions is complicated and requires a great deal of are projects for embedded system development, such as AU- work. As a consequence, most designers of external DSLs do TOSAR [15] and enterprise information systems [4, 6]. not include support for expressions in their DSL but provide Xtext is hosted at Eclipse.org3 and is distributed under some workarounds. A typical workaround is to define only the Eclipse Public Licence (EPL). With Xtext, the DSL the structural information in the DSL and add behavior by specification is defined in a grammar resembling EBNF from modifying or extending the generated code. It is obviously which parsers, linkers and other parts of the language in- frastructure are derived. We give an example of that in 2http://www.eclipse.org/Xtext/ 3http://eclipse.org/ Section 2.1. Section 2.2 explains how dependency injection Listing 2: A simple domain model language facilitates tool chain adaptability and Section 2.3 explains 1 grammar org.example.domainmodel.DomainModel with org. how language inheritance works with Xtext. eclipse.xtext.common.Terminals 2 2.1 A Simple Domain Model Language 3 generate domainmodel "http://www.example.org/ domainmodel/Domainmodel" As an example of how to build DSLs using Xtext, we 4 present a simple language to define domain models. The 5 Domainmodel : language is able to describe entities and their relations.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-