Domain-Specific Languages

45
Domain-Specific Languages Tijs van der Storm Monday, January 23, 12

Transcript of Domain-Specific Languages

Page 1: Domain-Specific Languages

Domain-Specific Languages

Tijs van der Storm

Monday, January 23, 12

Page 2: Domain-Specific Languages

Some facts

Robert Glass, Facts and fallacies of Software Engineering, Addison-Wesley 2003

Monday, January 23, 12

Page 3: Domain-Specific Languages

Reuse?

Monday, January 23, 12

Page 4: Domain-Specific Languages

Reuse?

Monday, January 23, 12

Page 5: Domain-Specific Languages

Reuse?

Monday, January 23, 12

Page 6: Domain-Specific Languages

Reuse?

Domain Specific Languages!

Monday, January 23, 12

Page 7: Domain-Specific Languages

Domain specific languages

Monday, January 23, 12

Page 8: Domain-Specific Languages

Domain specific languages

Monday, January 23, 12

Page 9: Domain-Specific Languages

Observations

• Special purpose

• Restricted

• Concise

• Expert usage

• Formalized

• Textual or graphic or combination

Monday, January 23, 12

Page 10: Domain-Specific Languages

General purpose languages (GPLs)

Monday, January 23, 12

Page 11: Domain-Specific Languages

DSLs

Monday, January 23, 12

Page 12: Domain-Specific Languages

Programming

CodeDomain Programmer

Monday, January 23, 12

Page 13: Domain-Specific Languages

Programming

Domain CodeProgrammer

Monday, January 23, 12

Page 14: Domain-Specific Languages

Programming is “lossy”

• encoding

• obfuscating

• encrypting

• dispersing

• tangling

• distorting

Monday, January 23, 12

Page 15: Domain-Specific Languages

Time consuming

Monday, January 23, 12

Page 16: Domain-Specific Languages

Change is error-prone

Monday, January 23, 12

Page 17: Domain-Specific Languages

Cognitive distance

?

Monday, January 23, 12

Page 18: Domain-Specific Languages

Design reuse is hard

Monday, January 23, 12

Page 19: Domain-Specific Languages

Design reuse

Monday, January 23, 12

Page 20: Domain-Specific Languages

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

Page 21: Domain-Specific Languages

Abstraction

Mondrian’s Pier and OceanPier and ocean

Monday, January 23, 12

Page 22: Domain-Specific Languages

Modeling the domain

Ceci n’est pas une vache

domain analysis

Monday, January 23, 12

Page 23: Domain-Specific Languages

System families

Monday, January 23, 12

Page 24: Domain-Specific Languages

Domain Specific Languages

formalizednotation capturing “Cows”

=

variationpoints

Monday, January 23, 12

Page 25: Domain-Specific Languages

Domain Specific Languages

grammar,template,

metamodel=

sentence,instance,model

=

Monday, January 23, 12

Page 26: Domain-Specific Languages

Code generation

Code generator Code

Monday, January 23, 12

Page 27: Domain-Specific Languages

APT: numerical controlfrom

the ’50s (!)

Monday, January 23, 12

Page 28: Domain-Specific Languages

SDF: Syntax definitionDeveloped

at CWI/UvA

Monday, January 23, 12

Page 29: Domain-Specific Languages

LaTeX: document preparation

Monday, January 23, 12

Page 30: Domain-Specific Languages

VHDL: hardware description

Monday, January 23, 12

Page 31: Domain-Specific Languages

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

Page 32: Domain-Specific Languages

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

Page 33: Domain-Specific Languages

DSL Implementation

Monday, January 23, 12

Page 34: Domain-Specific Languages

DSL Code

cow spots false color orangeend

cow spots true color brownend

cow spots true color blackend

Monday, January 23, 12

Page 35: Domain-Specific Languages

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

Page 36: Domain-Specific Languages

Advantages

• No need to write/maintain parser

• Host language available if needed

• Use of existing tools (IDE) etc.

Monday, January 23, 12

Page 37: Domain-Specific Languages

Drawbacks

• Restricted to host language

• Less static checking

• Less opportunity for optimization/analysis

Monday, January 23, 12

Page 38: Domain-Specific Languages

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

Page 39: Domain-Specific Languages

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

Page 40: Domain-Specific Languages

Parsing

cow spots false color orangeend

parse

whitespaceomitted

Cow

Prop*

Prop Prop

Bool Color“spots” “color”

“orange”“false”Monday, January 23, 12

Page 41: Domain-Specific Languages

Abstract syntax tree (AST)

spots color

orangefalse

CowCow

Prop*

Prop Prop

Bool Color“spots” “color”

“orange”“false”

implode

Monday, January 23, 12

Page 42: Domain-Specific Languages

Semantic analysis

spots color

orangetrue

Cow

check

Constraint:

Monday, January 23, 12

Page 43: Domain-Specific Languages

Code generation

generatespots color

orangefalse

Cow

Monday, January 23, 12

Page 44: Domain-Specific Languages

• Parser generators

• Attribute grammar systems

• Transformation systems

• Language workbenches

Tools

Monday, January 23, 12

Page 45: Domain-Specific Languages

Rascal

• parsing

• analysis

• transformation

• generation

Monday, January 23, 12