creating a textual domain specific language
TRANSCRIPT
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Software ArchitecturePart III
Class #2
Creating a domain-specific language
Vicente García Díaz2014
University of Oviedo
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
What is a domain-specific language?
• It is a programming language that focuses only on a particular domain
• The domain can be anything
• Opposite ideas▫ General-Purpose Language (GPL)
Java, C, C++, C#, Python, UML, …
▫ Domain-Specific Language (DSL)
CSS, HTML, SQL
2
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Classification (I)
• From the point of view of how the language is
3
Textuals Graphicals
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Classification (II)
• From the point of view of the problem domain
4
Horizontals Verticals
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Stakeholders
5
Engineers
Clients
Developers
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Limits
• It is desirable to set limits to determine which parts of the system will be created with a DSL and which parts will not
• Sometimes it is better to use a GPL and other times it is better to use a DSL
• Using DLSs has both advantages and disadvantages
6
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Benefits of using DSLs
1. With a DSL, it is more difficult to make mistakes in the representation of a problem domain
2. Working with the terms of a specific domain facilitates the understanding of the models that represents the software to non-experts in computer technology development
3. When knowledge of a particular domain is captured in a model, it becomes much easier to perform migrations between different technologies
7
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Drawbacks of using DSLs
1. Research time to define and design the DSL thatwill be created
2. Cost required to test the DSL
3. Additional difficulties in the application deployment
4. Need for additional documentation
5. Preparation of the development team
8
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
How a DSL is usually created?
• They are usually created using parser generators▫ From a grammar they obtain the parser
▫ ANTLR, JavaCC, Lexx/yacc, …
• The parser validates the text
and created a tree▫ It is usually an Abstract
Syntax Tree (AST)
9
addition
multiplication literal
literal literal
255 6
5*6 + 25
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
A difficult task
• Writing a parser is a difficult task▫ Even using tools like ANTLR
• …a we would still need:▫ Creating a development environment for the language
▫ Transform the AST in “something” from which we are able to generate code
• It is better not to do it “by hand”▫ Textual Modeling Framework we will focus on
▫ Graphical Modeling Framework
10
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
What is Xtext?
• It is a tool to build DSLs or even GPLs
• It automatically generates various artifacts from a LL(*) grammar ▫ A parser
▫ A Ecore metamodel
▫ An IDE for Eclipse
Syntax highlighting
Assistance in completing sentences
Overview window
Checking of constrains in real time
11
Generador
Xtext
Metamodelo
Ecore
Gramática Xtext
(Petri.xtext)
Parser ANTLR
Editor Plug-in
Proyecto del DSL “Petri”
Proyecto UI
Xtextgrammar
ANTL Parser
Ecoremetamodel
Plugingfor
Eclipse
Xtextgenerator
DSL Project
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
What is our goal with Xtext?
1. Creating a domain-specific language (textual) based on Xtext
2. Creating programs (models) using the createdlanguage
3. Generaring artifacts from the models (e.g., Java source code, HTML, plain text, assembly code, …)
12
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Developing process with Xtext
1. Part I. Creation of the language▫ Step 1. Creating a Xtext Project in Eclipse▫ Step 2. Defining the gramar of the language…and many
other things▫ Step 3. Generating the language of all of its components
2. Part II. Creation of programs (models) with the new language
▫ Step 1. Opening the development environment of thelanguage
▫ Step 2. Creating a program for the new language usingthe development environment
3. Part III. Generation of artifacts from the models
13
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Installing the environment. Option 1
• Download Eclipse for Xtext
• http://www.eclipse.org/Xtext/download.html
14
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Installing the environment. Option 2
• Download Eclipse Modeling Tools
• http://www.eclipse.org/downloads/packages/eclipse-modeling-tools/lunasr1
15
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Installing the environment. Option 3
• Install Xtext as a plugin for the Eclipse IDE
16
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do
Software ArchitectureS
ch
oo
l o
f C
om
pu
ter
Sc
ien
ce
Un
ive
rsit
y o
f O
vie
do Creating a domain-specific language
Thank you