Dev Dives: Streamline document processing with UiPath Studio Web
Domain Specific Language Design
1. DSL Design
A conceptual framework
for building good DSLs
Markus Voelter
based on material
independent/itemis from a paper written
voelter@acm.org with Eelco Visser
www.voelter.de E.Visser@tudelft.nl
voelterblog.blogspot.de http://eelcovisser.org/
@markusvoelter
+Markus Voelter
3. A DSL is a focussed, processable
language for describing a
specific concern when building a
system in a specific domain. The
abstractions and notations used
are natural/suitable for the
stakeholders who specify that
particular concern.
4. more in GPLs more in DSL
Domain Size large and complex smaller and well-defined
Designed by guru or committee a few engineers and
domain experts
Language Size large small
Turing- almost always often not
completeness
User Community large, anonymous and small, accessible and
widespread local
In-language sophisticated limited
abstraction
Lifespan years to decades months to years (driven
by context)
Evolution slow, often fast-paced
standardized
Incompatible almost impossible feasible
Changes
5. General Purpose
C
Components
Domain
State Machines Specific
Sensor Access
LEGO Robot
Control
6. Modular Language
a b c
d e f
my
L g h i
j k l
with many optional,
composable modules
18. Model
A schematic description of a
system, theory, or
phenomenon that accounts for
its known or inferred
properties and may be used
for further study of its
characteristics
www.answers.com/topic/mode
l
19. Model
A representation of a set of
components of a process,
system, or subject area,
generally developed for
understanding, analysis,
improvement, and/or
replacement of the process
www.ichnet.org/glossary.htm
20. Model
which ones?
an abstraction or
simplification of
reality
what should
we leave out? ecosurvey.gmu.edu/glossary.ht
m
21. Model
Purpose
… code generation
… analysis and checking
… platform independence
… stakeholder integration
…
drives design of
language!
22. Model
Purpose
… code generation
… analysis and checking
… platform independence
… stakeholder integration
Example
Compo
nents
23. Model
Purpose
… code generation
… analysis and checking
… platform independence
… stakeholder integration
Example
Refrigerators Refrige
rators
24. Model
Purpose
… code generation
… analysis and checking
… platform independence
… stakeholder integration
Example
Extended C Exten
ded C
25. Model
Purpose
… code generation
… analysis and checking
… platform independence
… stakeholder integration
Example
Pension
Plans
26. body of
knowledge
deductive
top down in the real
world
Domain
inductive
existing bottom up
software
(family)
27. body of
knowledge
deductive
top down in the real
world
Domain
Example Example
Refrigerators Penion
Plans
Refrige
rators
28. Domain
Domain
inductive
existing bottom up
software Example Example
(family) Exten Compo
ded C netns
29. A DSL LD for D is a
language that is
specialized to en-
coding PD programs.
more efficient
smaller
59. Def: DSL
A DSL is a language at D that
provides linguistic abstractions
for common patterns and idioms
of a language at D-1 when used
within the domain D.
60. Def: DSL cont’d
A good DSL does not require the
use of patterns and idioms to
express semantically interesting
concepts in D.
Processing tools do not have to
do “semantic recovery” on D
programs.
Declarative!
74. Def: Coverage
why would CD(L) be != 1?
1) L is deficient
2) L is intended to cover
only a subset of D,
corner cases may make L
too complex
Rest must be expressed in D-1
76. Def: Coverage
Only a particular style of
web apps are suported.
Many more are conceivable.
Example
WebDSL
77. Def: Coverage
DSLs are continuously evolved
so the relevant parts of the
deductive domain are
supported.
Example Example Example
Compo Refrige Pension
nents rators Plans
78. Semantics &
Execution
expressivity completeness
coverage paradigms
semantics modularity
separation of concrete
concerns syntax
process
84. Unique State Names
Unreachable States
Dead End States
…
Easier to do on a
declarative Level!
Thinking of all
Example
constraints is a
Exten
coverage problem!
ded C
85. Assign fixed types
Derive Types
Calculate Common
Types
Check Type Consistency
What does a type system do?
86. Intent + Derive
Check
More code More convenient
Better error More complex
messages checkers
Better Performance Harder to
understand for
users
101. Multi-Stage: Reuse
L3 Robot Control
State Machine
L2 L5 Components
L1 C (MPS tree)
Example
L0 C Text Exten
ded C
102. Multi-Stage: Reuse
L3 Robot Control
State Machine
Consistency
Model Checking
L2 L5 Components
Efficient Mappings
C Type System
L1 C (MPS tree)
Syntactic
Correctness, Example
Headers
L0 C Text Exten
ded C
110. Interpretation
A program at D0 that
acts on the structure
of an input program at D>0
imperative step through
functional eval recursively
declarative ? solver ?
122. Multiple Mappings
… alternatively, selectably
Extend LD to include
LD explicit data that
determines
transformation
Lx Ly Lz
123. Multiple Mappings
… alternatively, selectably
Extend LD to include
LD explicit data that
determines
transformation
Lx Ly Lz Example
Restricted Port leads
to reduced overhead Exten
C ded C
125. Multiple Mappings
… alternatively, selectably
External Data:
LD - Switches
- Annotation Model
Switch
Control Java
vs. C
Lx Ly Lz Example
Pension
Plans
126. Multiple Mappings
… alternatively, selectably
Heuristics: Analyze
LD model to try to
decide
Lx Ly Lz
127. Multiple Mappings
… alternatively, selectably
T LD TESTING!
Lx Ly Lz
T T T
153. Manually written code?
Call “black box” code
(foreign functions)
Embed LD-1 code in LD program
Embed C statements
in components, state machines
or decision tables Example
Refrige
rators
154. Manually written code?
Call “black box” code
(foreign functions)
Embed LD-1 code in LD program
Use composition mechanisms of
LD-1 (inheritance, patterns, aspects, …)
155. Manually written code?
Call “black box” code
(foreign functions)
Embed LD-1 code in LD program
Use composition mechanisms of
LD-1 (inheritance, patterns, aspects, …)
Generate base classes Example
with abstract methods; Compo
implement in subclass nents
156. Manually written code?
Call “black box” code
(foreign functions)
Embed LD-1 code in LD program
Use composition mechanisms of
LD-1 (inheritance, patterns, aspects, …)
Use protected regions (if you
really have to…)
157. Manually written code?
Call “black box” code
(foreign functions)
Embed LD-1 code in LD program
Use composition mechanisms of
LD-1 (inheritance, patterns, aspects, …)
Use protected regions (if you
really have to…) DON’T!
158. Incomplete: When?
Good for technical Example Example
DSLs: Devs write Exten Compo
LD-1 code ded C nents
Bad for business DSLs.
Maybe use a LD-1 std lib that LD
code can call into?
Example Example Example
Refrige Pension Web
rators Plans DSL
159. Prevent Breaking Promises!
class B extens BBase {
public void doSomething() {
Registry.get(„A“).someMethod();
}
}
173. Structure
Specialization
Liskov substitution P
leaving holes (“abstract”)
variants (in space)
evolution (over time)
174. Structure
Specialization
Pension Plans can inherit
from other plans.
Rules can be abstract;
Plans with abstract Example
rules are abstact
Pension
Plans
180. Behavior
Functional
functions call other functions.
no state. No aliasing.
write understand debug analyze performance
simple - simple simpl good good -
e
183. Behavior
Functional
pure expressions are
a subset of functional
(operators hard-wired)
guards
preconditions
derived attributes
184. Behavior
Declarative
only facts and goals.
no control flow.
eval engine, solver (several)
write understand debug analyze performance
simple simple - hard depends often bad
188. Behavior
Reactive
reactions to events, more
events are produced.
Communication via
events and channels/queues
write understand debu analyze performance
g
simple simple/har hard simple can be good
190. Behavior
Data Flow
chained blocks consume
continuous data that flows
from block to block
write understand debu analyze performance
g
simple - simple/har hard simple can be good
193. Behavior
State Based
states, transitions,
guards, reactions
event driven, timed
write understand debu analyze performance
g
simple - simple/har s/h simple + can be good
202. Language Modularity,
Behavior and Reuse (LMR&C)
Composition
increase efficiency
of DSL development
4 ways of composition:
Referencing
Reuse
Extension
Reuse
203. Language Modularity,
Behavior and Reuse (LMR&C)
Composition
increase efficiency
of DSL development
4 ways of composition:
distinguished regarding
dependencies and fragment
structure
205. Dependencies:
Behavior
do we have to know about the
reuse when designing the
languages?
Fragment Structure:
homogeneous vs. heterogeneous
(„mixing languages“)
226. Challenges - Syntax
Behavior and Embedding
Extension
requires modular concrete
syntax
Many tools/formalisms cannot
do that
227. Challenges – Type Systems
Behavior the type system of
Extension:
the base language must be
designed to be extensible/
overridable
228. Challenges – Type Systems
Behavior
Reuse and Embedding: Rules that
affect the interplay can reside
in the adapter language.
229. Challenges – Trafo & Gen
Referencing (I)
Behavior
Written
specifically Can be
for the Reused
combination
Two separate, dependent
single-source transformations
230. Challenges – Trafo & Gen
Referencing (II)
A single multi-sourced
transformation
231. Challenges – Trafo & Gen
Referencing (III)
A preprocessing trafo that changes the
referenced frag in a way specified by
the referencing frag
232. Challenges – Trafo & Gen
Extension
Transformation by assimiliation, i.e.
generating code in the host lang
from code expr in the extension lang.
259. DSL as a Product
Release Plan
Bug Tracker
Testing!
Support
Documentation
260. Reviews
Reviews become
easier --- less
code, more
domain-specific
261. The End.
This material is part of my
upcoming (early 2013) book
DSL Engineering with
Language Workbenches
Stay in touch; it will be cheap or
maybe even free :-)
www.voelter.de/dslbook
@markusvoelter
+Markus Voelter