domain-specific languages
TRANSCRIPT
Domain-Specific Languages
Tijs van der Storm
Monday, January 23, 12
Some facts
Robert Glass, Facts and fallacies of Software Engineering, Addison-Wesley 2003
Monday, January 23, 12
Reuse?
Monday, January 23, 12
Reuse?
Monday, January 23, 12
Reuse?
Monday, January 23, 12
Reuse?
Domain Specific Languages!
Monday, January 23, 12
Domain specific languages
Monday, January 23, 12
Domain specific languages
Monday, January 23, 12
Observations
• Special purpose
• Restricted
• Concise
• Expert usage
• Formalized
• Textual or graphic or combination
Monday, January 23, 12
General purpose languages (GPLs)
Monday, January 23, 12
DSLs
Monday, January 23, 12
Programming
CodeDomain Programmer
Monday, January 23, 12
Programming
Domain CodeProgrammer
Monday, January 23, 12
Programming is “lossy”
• encoding
• obfuscating
• encrypting
• dispersing
• tangling
• distorting
Monday, January 23, 12
Time consuming
Monday, January 23, 12
Change is error-prone
Monday, January 23, 12
Cognitive distance
?
Monday, January 23, 12
Design reuse is hard
Monday, January 23, 12
Design reuse
Monday, January 23, 12
The problem
• a lot of code,
• low level code,
• characterized by lack of abstraction
• encoding domain knowledge
• and encoding design knowledge
Monday, January 23, 12
Abstraction
Mondrian’s Pier and OceanPier and ocean
Monday, January 23, 12
Modeling the domain
Ceci n’est pas une vache
domain analysis
Monday, January 23, 12
System families
Monday, January 23, 12
Domain Specific Languages
formalizednotation capturing “Cows”
=
variationpoints
Monday, January 23, 12
Domain Specific Languages
grammar,template,
metamodel=
sentence,instance,model
=
Monday, January 23, 12
Code generation
Code generator Code
Monday, January 23, 12
APT: numerical controlfrom
the ’50s (!)
Monday, January 23, 12
SDF: Syntax definitionDeveloped
at CWI/UvA
Monday, January 23, 12
LaTeX: document preparation
Monday, January 23, 12
VHDL: hardware description
Monday, January 23, 12
Risla: financial productsDeveloped
at CWIproduct LOAN
declaration contract data PAMOUNT : amount %% Principal Amount STARTDATE : date %% Starting date MATURDATE : date %% Maturity data INTRATE : int-rate %% Interest rate RDMLIST := [] : cashflow-list %% List of redemptions.
information PAF : cashflow-list %% Principal Amount Flow IAF : cashflow-list %% Interest Amount Flow
registration %% Register one redemption. RDM(AMOUNT : amount, DATE : date)
Time to market went down from 3 months to 3 weeks.
Monday, January 23, 12
Other examples• Make: software building
• Dot: graph visualization
• SQL: relational querying
• SWUL: Swing GUIs
• HTML: hypertext
• CLOPS: commandline options
• GNUPlot: plotting
• R: statistics
• CML: kernel config
• Lex: lexical scanning
• Excel: spreadheets
• Rascal: meta-programming
• ...
Monday, January 23, 12
DSL Implementation
Monday, January 23, 12
DSL Code
cow spots false color orangeend
cow spots true color brownend
cow spots true color blackend
Monday, January 23, 12
Embedding
cow spots false color orangeend
cow do spots false color :orangeend
(cow spots #t color 'orange)
new Cow() .spots(false) .color("orange").end();
Monday, January 23, 12
Advantages
• No need to write/maintain parser
• Host language available if needed
• Use of existing tools (IDE) etc.
Monday, January 23, 12
Drawbacks
• Restricted to host language
• Less static checking
• Less opportunity for optimization/analysis
Monday, January 23, 12
Syntax definition
Cow ::= “cow” Prop* “end”Prop ::= “horns” Bool | “spots” Bool | “color” ColorBool ::= “true” | “false”Color ::= “black” | “brown” | “orange”
Repetition
literal
alternative
Monday, January 23, 12
Parser generation
Cow ::= “cow” Prop* “end”Prop ::= “horns” Bool | “spots” Bool | “color” ColorBool ::= “true” | “false”Color ::= “black” | “brown” | “orange”
javacupantlrRats!
yaccbisonlemon
parse.exe
Grammar Parser
Monday, January 23, 12
Parsing
cow spots false color orangeend
parse
whitespaceomitted
Cow
Prop*
Prop Prop
Bool Color“spots” “color”
“orange”“false”Monday, January 23, 12
Abstract syntax tree (AST)
spots color
orangefalse
CowCow
Prop*
Prop Prop
Bool Color“spots” “color”
“orange”“false”
implode
Monday, January 23, 12
Semantic analysis
spots color
orangetrue
Cow
check
Constraint:
Monday, January 23, 12
Code generation
generatespots color
orangefalse
Cow
Monday, January 23, 12
• Parser generators
• Attribute grammar systems
• Transformation systems
• Language workbenches
Tools
Monday, January 23, 12
Rascal
• parsing
• analysis
• transformation
• generation
Monday, January 23, 12