The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
Creating a textual domain specific language
1. Software Architecture
School of Computer Science University of Oviedo
University of Oviedo
Software Architecture
Part III
Class #2
Creating a domain-specific
language
2014 Vicente García Díaz
2. Software Architecture
School of Computer Science University of Oviedo
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
3. Software Architecture
School of Computer Science University of Oviedo
Classification (I)
• From the point of view of how the language is
3
Textuals Graphicals
4. Software Architecture
School of Computer Science University of Oviedo
Classification (II)
• From the point of view of the problem domain
4
Horizontals Verticals
5. Software Architecture
School of Computer Science University of Oviedo
Stakeholders
5
Engineers
Developers
Clients
6. Software Architecture
School of Computer Science University of Oviedo
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
7. Software Architecture
School of Computer Science University of Oviedo
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
7
captured in a model, it becomes much easier to
perform migrations between different technologies
8. Software Architecture
School of Computer Science University of Oviedo
Drawbacks of using DSLs
1. Research time to define and design the DSL that
will 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
9. Software Architecture
School of Computer Science University of Oviedo
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
5*6 + 25
multiplication literal
literal literal
5 6 25
10. Software Architecture
School of Computer Science University of Oviedo
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
11. Software Architecture
School of Computer Science University of Oviedo
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
DSL Project
Generador
Xtext
Metamodelo
Ecore
Gramática Xtext
(Petri.xtext)
Parser ANTLR
Editor Plug-in
Proyecto del DSL “Petri”
Proyecto UI
Xtext
grammar
ANTL
Parser
Ecore
metamodel
Pluging
for
Eclipse
Xtext
generator
12. Software Architecture
School of Computer Science University of Oviedo
What is our goal with Xtext?
1. Creating a domain-specific language (textual)
based on Xtext
2. Creating programs (models) using the created
language
3. Generaring artifacts from the models (e.g., Java
12
source code, HTML, plain text, assembly code, …)
13. Software Architecture
School of Computer Science University of Oviedo
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 the
language
▫ Step 2. Creating a program for the new language using
the development environment
3. Part III. Generation of artifacts from the models
13
14. Software Architecture
School of Computer Science University of Oviedo
Installing the environment. Option 1
• Download Eclipse for Xtext
• http://www.eclipse.org/Xtext/download.html
14
15. Software Architecture
School of Computer Science University of Oviedo
Installing the environment. Option 2
15
• Download Eclipse Modeling Tools
• http://www.eclipse.org/downloads/packages/eclips
e-modeling-tools/lunasr1
16. Software Architecture
School of Computer Science University of Oviedo
Installing the environment. Option 3
• Install Xtext as a plugin for the Eclipse IDE
16