Domain Specific Language Design
Upcoming SlideShare
Loading in...5
×
 

Domain Specific Language Design

on

  • 1,272 views

 

Statistics

Views

Total Views
1,272
Views on SlideShare
1,272
Embed Views
0

Actions

Likes
3
Downloads
51
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Domain Specific Language Design Domain Specific Language Design Presentation Transcript

  • DSL DesignA conceptual frameworkfor 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
  • Introduction
  • A DSL is a focussed, processable language for describing aspecific concern when building asystem in a specific domain. Theabstractions and notations used are natural/suitable for the stakeholders who specify that particular concern.
  • more in GPLs more in DSLDomain Size large and complex smaller and well-definedDesigned by guru or committee a few engineers and domain expertsLanguage Size large smallTuring- almost always often notcompletenessUser Community large, anonymous and small, accessible and widespread localIn-language sophisticated limitedabstractionLifespan years to decades months to years (driven by context)Evolution slow, often fast-paced standardizedIncompatible almost impossible feasibleChanges
  • General PurposeC Components Domain State Machines Specific Sensor Access LEGO Robot Control
  • Modular Language  a b c d e f my L g h i j k l  with many optional,composable modules
  • Case Studies
  • ExampleCompo nents
  • ExampleCompo nents
  • ExampleRefrigerators Refrige rators
  • ExampleRefrigerators
  • ExampleRefrigerators
  • ExampleExtended C
  • ExamplePension Plans
  • ExamplePension Plans
  • Example Web DSL
  • Terms &Concepts
  • Model A schematic description of a system, theory, orphenomenon that accounts for its known or inferred properties and may be used for further study of its characteristics www.answers.com/topic/mode l
  • ModelA representation of a set of components of a process, system, or subject area, generally developed for understanding, analysis, improvement, and/orreplacement of the process www.ichnet.org/glossary.htm
  • Model which ones? an abstraction or simplification of realitywhat shouldwe leave out? ecosurvey.gmu.edu/glossary.ht m
  • Model Purpose… code generation… analysis and checking… platform independence… stakeholder integration… drives design of language!
  • Model Purpose… code generation… analysis and checking… platform independence… stakeholder integration Example Compo nents
  • Model Purpose… code generation… analysis and checking… platform independence… stakeholder integration Example Refrigerators Refrige rators
  • Model Purpose… code generation… analysis and checking… platform independence… stakeholder integration Example Extended C Exten ded C
  • Model Purpose… code generation… analysis and checking… platform independence… stakeholder integration Example Pension Plans
  • body of knowledge deductive top down in the real world Domain inductive existing bottom upsoftware (family)
  • body of knowledge deductive top down in the real world Domain Example ExampleRefrigerators Penion Plans Refrige rators
  • Domain Domain inductive existing bottom upsoftware Example Example (family) Exten Compo ded C netns
  • A DSL LD for D is a language that is specialized to en- coding PD programs.more efficientsmaller
  • Programsare trees elemen t
  • Fragments aresubtrees w/ root fragment root ffragment
  • Parent-ChildRelation f
  • Programsand Fragments f
  • Programs aregraphs, really. reference
  • Programs aregraphs, really.
  • Languages aresets of concepts C2 C1 Cn C3 L
  • Languages aresets of concepts C2 C1 Cn C3 L
  • Programsand languages C2 C1 Cn C3
  • Language:concept inheritance C2 L C1 1 L2 C3 C1
  • Languagedoes not depend onany other language IndependenceFragmentdoes not depend onany other fragment
  • Independence Example Refrige rators
  • HomogeneousFragmenteverything expressedwith one language
  • HeterogeneousHeterogeneous CStatemachines Testing Example Exten ded C
  • Domain Hierarchy
  • Domain Hierarchy avionics automotiveembeddedsoftware Example all programs Exten ded C
  • Design Dimensionsexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • Expressivityexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • ShorterPrograms MoreAccessibleSemantics
  • For a limited Domain! Domain Knowledgeencapsulated in language
  • Smaller DomainMore Specialized Language Shorter Programs
  • The do-what-I-want language Ѱ
  • Single Programvs. Class/Domain No Variability! Ѱ
  • Domain Hierarchy more specialized domainsmore specialized languages
  • Reification Dn+1 == Dn
  • Reification Transformation / Generation ==LanguageDefinition
  • Overspecification!Requires Semantic Analysis!
  • LinguisticAbstraction Declarative! Directly represents Semantics.
  • Def: DSLA DSL is a language at D thatprovides linguistic abstractionsfor common patterns and idiomsof a language at D-1 when usedwithin the domain D.
  • Def: DSL cont’dA good DSL does not require theuse of patterns and idioms toexpress semantically interestingconcepts in D.Processing tools do not have todo “semantic recovery” on Dprograms.Declarative!
  • Another Example Example Exten ded C
  • Another Example Example Exten Turing Complete! Requires Semantic Analysis! ded C
  • LinguisticAbstraction Example Exten ded C
  • LinguisticAbstraction Example Exten ded C
  • LinguisticAbstraction In-Language Abstraction Libraries Classes Frameworks
  • LinguisticAbstractionAnalyzableBetter IDE Support In-Language Abstraction User-Definable Simpler Language
  • LinguisticAbstraction SpecialAnalyzable Treatment!Better IDE Support In-Language Abstraction User-Definable Simpler Language
  • LinguisticAbstraction Std Lib In-Language Abstraction
  • Std Lib Example Refrige rators
  • Coverageexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • Domain DL definedinductively by L(the domain that can be expressed by L) CL(L) == 1 (by definition)not very interesting!
  • Def: Coverageto what extend can a languageL cover a domain D
  • Def: Coveragewhy 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
  • Def: CoverageCoverage is full.You call always write C. Example Exten ded C
  • Def: CoverageOnly a particular style ofweb apps are suported.Many more are conceivable. Example WebDSL
  • Def: CoverageDSLs are continuously evolvedso the relevant parts of thedeductive domain aresupported. Example Example Example Compo Refrige Pension nents rators Plans
  • Semantics & Executionexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • Static SemanticsExecution Semantics
  • Static SemanticsExecution Semantics
  • Static Semantics Constraints Type Systems
  • Unique State NamesUnreachable States Dead End States … Example Exten ded C
  • Unique State NamesUnreachable States Dead End States … Easier to do on a declarative Level! Example Exten ded C
  • Unique State Names Unreachable States Dead End States … Easier to do on a declarative Level!Thinking of all Exampleconstraints is a Extencoverage problem! ded C
  • Assign fixed typesDerive Types Calculate Common Types Check Type Consistency What does a type system do?
  • Intent + DeriveCheckMore code More convenientBetter error More complexmessages checkersBetter Performance Harder to understand for users
  • ExampleRefrigerators
  • What does it all mean?Execution Semantics
  • Def: Semantics … via mapping to lower levelOB: Observable Behaviour (Test Cases)
  • Def: Semantics … via mapping to lower level LD Transformation Interpretation LD-1
  • Transformation Dn+1 Dn
  • Transformation Example Exten ded C
  • Transformation LD Transformation LD-1 Known Semantics!
  • Transformation LD Correct!? Transformation LD-1
  • TransformationTests (D) LD TransformationTests (D-1) LD-1Run tests on both levels; all pass.Coverage Problem!
  • ExampleRefrigerators
  • Transformation Example Pension Plans
  • Behavior Example Refrige rators
  • Multi-Stage L3 L2 Modularization L1 L0
  • Multi-Stage: Reuse L3 L2 L5 L1 Reusing Later Stages L0 Optimizations!
  • Multi-Stage: Reuse L3 Robot Control State Machine L2 L5 Components L1 C (MPS tree) Example L0 C Text Exten ded C
  • 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
  • Multi-Stage: Reuse L3 Reusing Early Stages L2 Portability L1 L1b L0 L0b
  • Multi-Stage: Reuse L3 L2 L1 L1b Java C# Example L0 L0b Exten ded C
  • Multi-Stage:Preprocess Adding an optional, modular emergency stop feature
  • Platform
  • Platform Temporal Data Versioning Database Access Transactions Distribution (JEE) Example Pension Plans
  • Platform Data Collection HAL Device Drivers Example Refrige rators
  • InterpretationA program at D0 thatacts on the structureof an input program at D>0
  • InterpretationA program at D0 thatacts on the structureof an input program at D>0 imperative  step through functional  eval recursively declarative ? solver ?
  • ExamplePension Plans
  • ExampleRefrigerators
  • Behavior Example Refrige rators
  • InterpretationA program at D0 thatacts on the structureof an input program at D>0
  • InterpretationAn interpreter :-)
  • Transformation Interpretation+ Code Inspection + Turnaround Time+ Debugging + Runtime Change+ Performance & Optimization+ Platform Con- formance
  • Def: Semantics … via mapping to lower level LD Transformation Interpretation LD-1
  • Multiple Mappings … at the same time LD Similar Semantics? Lx Ly Lz
  • Multiple Mappings … at the same time LD T Similar Semantics? Lx Ly Lz T T T all green!
  • ExamplePension Plans
  • ExampleRefrigerators
  • Multiple Mappings … alternatively, selectably Extend LD to include LD explicit data that determines transformation Lx Ly Lz
  • 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
  • Multiple Mappings … alternatively, selectably External Data: LD - Switches - Annotation Model Lx Ly Lz
  • Multiple Mappings … alternatively, selectably External Data: LD - Switches - Annotation Model Switch Control Java vs. C Lx Ly Lz Example Pension Plans
  • Multiple Mappings … alternatively, selectably Heuristics: Analyze LD model to try to decide Lx Ly Lz
  • Multiple Mappings … alternatively, selectably T LD TESTING! Lx Ly Lz T T T
  • Reduced Expressiveness bad? maybe. good? maybe! Model Checking SAT Solving Exhaustive Search, Proof!
  • Unique State Names Unreachable States Dead End States Guard Decidability ReachabilityExhaustive Search, Proof!
  • ExampleExtended C
  • ExampleExtended C
  • Separation of Concernsexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • Several Concerns … in one domain
  • Several Concerns … in one domain integrated into separated into one fragment several fragments
  • Viewpoints independent dependent
  • Viewpoints Hardware Behavior Tests Example Refrige rators
  • Viewpoints: Why? Sufficiency Different Stakeholders Different Steps in Proces – VCS unit!
  • Viewpoints Hardware Product Management Behaviour Thermo- dynamics- Experts Tests Example Refrige rators
  • Viewpoints independent sufficient? contains all the data for running a meaningful transformation
  • Viewpoints sufficient implementation code sufficient Hardware structure documentation Example Refrige rators
  • Viewpoints: Why? 1:n Relationships
  • Viewpoints 1:n Hardware Behaviour Tests Example Refrige rators
  • Viewpoints Well-defined Dependencies No Cycles! Avoid Synchronization! (unless you use a projectional editor)
  • Viewpoints: Why? LD LAnnotation LD-1
  • Progressive Refinement
  • Views on Programs Example Pension Plans
  • Completenessexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • Can you generate 100% ofthe code from the DSLprogram?More generally: all of D-1
  • Semantics:Introduce G (“generator”): complete incomplete
  • Incomplete: What to do? FD OB(FD) != FD-1
  • Incomplete: What to do?Manually written code! FD OB(FD) == FD-1 + FD-1, man
  • Manually written code?Call “black box” code(foreign functions)Embed LD-1 code in LD program
  • 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
  • Manually written code?Call “black box” code(foreign functions)Embed LD-1 code in LD programUse composition mechanisms ofLD-1 (inheritance, patterns, aspects, …)
  • Manually written code?Call “black box” code(foreign functions)Embed LD-1 code in LD programUse composition mechanisms ofLD-1 (inheritance, patterns, aspects, …)Generate base classes Examplewith abstract methods; Compoimplement in subclass nents
  • Manually written code?Call “black box” code(foreign functions)Embed LD-1 code in LD programUse composition mechanisms ofLD-1 (inheritance, patterns, aspects, …)Use protected regions (if youreally have to…)
  • Manually written code?Call “black box” code(foreign functions)Embed LD-1 code in LD programUse composition mechanisms ofLD-1 (inheritance, patterns, aspects, …)Use protected regions (if youreally have to…) DON’T!
  • Incomplete: When?Good for technical Example ExampleDSLs: Devs write Exten CompoLD-1 code ded C nentsBad for business DSLs.Maybe use a LD-1 std lib that LDcode can call into?Example Example ExampleRefrige Pension Webrators Plans DSL
  • Prevent Breaking Promises! class B extens BBase { public void doSomething() { Registry.get(„A“).someMethod(); } }
  • Prevent Breaking Promises!Better: Dependency Injection Example Static analysis tools Compo nents
  • Roundtripping LD L’D LD-1 ……… D-1 L’
  • Roundtripping – Don’t! LD L’D Semantic Recovery! LD-1 ……… D-1 L’
  • Fundamental Paradigmsexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • StructureModularization, Visibility Namespaces, public/private importing
  • StructureModularization, Visibility Namespaces, public/private importing divide & conquer reuse stakeholder integration
  • StructurePartitioning (Files) VCS Unit Unit of sharing Unit of IP != logical modules may influence language design
  • StructureModularization, Visibility Example Exten ded C
  • StructureModularization, Visibility Example Compo nents
  • StructurePartitioning (Files) change impact link storage model organization tool integration
  • StructureSpec vs. Implementation plug in different Impls different stakeholders
  • StructureSpec vs. Impl. Example Exten ded C
  • StructureSpecialization Liskov substitution P leaving holes (“abstract”)
  • StructureSpecialization Liskov substitution P leaving holes (“abstract”) variants (in space) evolution (over time)
  • StructureSpecialization Pension Plans can inherit from other plans. Rules can be abstract; Plans with abstract Example rules are abstact Pension Plans
  • StructureSuperposition, Aspects merging overlay AOP modularize cross-cuts
  • StructureSuperposition, Aspects Example Compo nents
  • BehaviorNot all DSLs specify behaviorSome just declare behavior This section is not for those!
  • BehaviorImperative sequence of statements changes program state write understand debug analyze performance simple simple - simpl hard good e
  • BehaviorImperative sequence of statements changes program state Example Refrige rators
  • BehaviorFunctional functions call other functions. no state. No aliasing. write understand debug analyze performance simple - simple simpl good good - e
  • BehaviorFunctional functions call other functions. no state. No aliasing. Example Pension Plans
  • BehaviorFunctional Example Pension Plans
  • BehaviorFunctional pure expressions are a subset of functional (operators hard-wired) guards preconditions derived attributes
  • BehaviorDeclarative only facts and goals. no control flow. eval engine, solver (several) write understand debug analyze performance simple simple - hard depends often bad
  • BehaviorDeclarative concurrency constraint programming solving logic programming
  • BehaviorDeclarative only facts and goals. no control flow. eval engine, solver (several) Example Web DSL
  • BehaviorDeclarative Example Exten ded C
  • BehaviorReactive 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
  • Behavior Reactive Example Refrige rators
  • BehaviorData Flow chained blocks consume continuous data that flows from block to blockwrite understand debu analyze performance gsimple - simple/har hard simple can be good
  • BehaviorData Flow continuous, calc on change quantized, calc on new data time triggered, calc every x
  • BehaviorData Flow Embedded Programming Enterprise ETL & CEP
  • BehaviorState Based states, transitions, guards, reactions event driven, timed write understand debu analyze performance g simple - simple/har s/h simple + can be good
  • BehaviorState Based Example Refrige rators
  • BehaviorCombinations data flow uses functional, imperative or declarative lang inside block
  • BehaviorCombinations state machines use expressions in guards and often an imperative lang in actions
  • BehaviorCombinations Example Refrige rators
  • Behavior
  • BehaviorCombinations purely structural languages often use expressions to specify constraints Example Exten ded C
  • Language Modularityexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • Language Modularity,Behavior and Reuse (LMR&C)Composition increase efficiency of DSL development
  • Language Modularity,Behavior and Reuse (LMR&C)Composition increase efficiency of DSL development4 ways of composition: Referencing Reuse Extension Reuse
  • Language Modularity,Behavior and Reuse (LMR&C)Composition increase efficiency of DSL development4 ways of composition: distinguished regarding dependencies and fragment structure
  • Dependencies:Behavior do we have to know about the reuse when designing the languages?
  • Dependencies:Behavior do we have to know about the reuse when designing the languages?Fragment Structure: homogeneous vs. heterogeneous („mixing languages“)
  • Dependencies &BehaviorFragment Structure:
  • Dependencies &BehaviorFragment Structure:
  • ReferencingReferencing
  • ReferencingReferencing Dependen t No containment
  • Referencing Used in Viewpoints
  • Referencing Fragment Fragment Fragment
  • Referencing Example Refrige rators
  • Extension Dependen t Containment
  • ExtensionExtension more specialized domains more specialized languages
  • Extension Dn+1 == Dn
  • Extension Dn+1 == Dn
  • Extension Good for bottom-up (inductive) domains, and for use by technical DSLs (people) == Dn
  • ExtensionDrawbacksBehavior tightly bound to base potentially hard to analyze the combined program
  • Extension Example Exten ded C
  • ExtensionExtension Example Exten ded C
  • Reuse Reuse Independent No containment
  • Reuse ReuseBehavior referenced language Often the is built expecting it will be reused. Hooks may be added.
  • Embedding Independent Containment
  • Embedding Example Pension Plans
  • EmbeddingBehavior Embedding often uses Extension to extend the embedded language to adapt it to its new context.
  • Challenges - SyntaxBehavior and Embedding Extension requires modular concrete syntax Many tools/formalisms cannot do that
  • Challenges – Type SystemsBehavior the type system of Extension: the base language must be designed to be extensible/ overridable
  • Challenges – Type SystemsBehavior Reuse and Embedding: Rules that affect the interplay can reside in the adapter language.
  • Challenges – Trafo & GenReferencing (I)BehaviorWrittenspecifically Can befor the Reusedcombination Two separate, dependent single-source transformations
  • Challenges – Trafo & GenReferencing (II) A single multi-sourced transformation
  • Challenges – Trafo & GenReferencing (III)A preprocessing trafo that changes the referenced frag in a way specified by the referencing frag
  • Challenges – Trafo & GenExtension Transformation by assimiliation, i.e. generating code in the host lang from code expr in the extension lang.
  • Challenges – Trafo & GenExtension Example Exten ded C
  • Challenges – Trafo & GenReuse (I) Reuse of existing transformations for both fragments plus generation of adapter code
  • Challenges – Trafo & GenReuse (II) composing transformations
  • Challenges – Trafo & GenReuse (III) generating separate artifacts plus a weaving specification
  • Challenges – Trafo & GenEmbedding (I) a purely embeddable language may not come with a generator. Assimilation (as with Extension)
  • Challenges – Trafo & GenEmbedding (II) Adapter language can coordinate thetransformations for the host and for the emebedded languages.
  • Concrete Syntaxexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • UI for the language!Important for acceptance by users! Textual Symbolic Tabular Graphical
  • Reuse existingsyntax ofdomain, if any!Tools let youfreely combineall kinds.
  • Default: Text Editors simple to build Productive Easy to integrate w/ tools Easy to evolve programs
  • Default: Text Editors simple to build Productive Easy to integrate w/ tools Easy to evolve programs… then add other forms,if really necessary
  • Graphical in case… Relationships
  • Graphical in case… Flow and Depenency
  • Graphical in case… Causality and Timing
  • Symbolic EitherMathematical, or often highly inspired by domain
  • Tables
  • Combinations
  • Combinations
  • Combinations
  • Combinations
  • Processexpressivity completenesscoverage paradigmssemantics modularityseparation of concrete concerns syntax process
  • Domain Analysis Interview Experts Get Structure their Feedback Knowledge Create Build the Examples Language
  • Iterate to goal
  • Documentation Create example- based tutorials!
  • Domain FolksProgramming? Precision vs. Algorithmics!
  • Domain FolksProgramming? DU Coding DU/Dev Paired Dev Coding DU Reviewing
  • DSL as a Product Release Plan Bug Tracker Testing! Support Documentation
  • Reviews Reviews become easier --- less code, more domain-specific
  • The End. This material is part of my upcoming (early 2013) book DSL Engineering with Language WorkbenchesStay in touch; it will be cheap or maybe even free :-)www.voelter.de/dslbook @markusvoelter +Markus Voelter