Domain-Specific Languages with


                              Sven Efftinge




copyright 2008 by itemis AG
Kiel, Germany
Jan   Peter




         Dennis
“... won’t talk
     about
model-driven
     stuff”
You’re lucky!
No UML!
No MDA!




No meta meta
meta meta ...
Hands-on a

concrete example
taken from Martin Fowler’s upcoming
         Book on DSLs
You’re working for a company
   specialized on systems for
secret compartments
Your customer:
Mrs. H
she likes secrets
To open the secret compartment, she has to
To open the secret compartment, she has to

               close the door,
To open the secret compartment, she has to

               close the door,

  open the second draw in
               her c...
To open the secret compartment, she has to

                close the door,

  open the second draw in
                her...
events
 doorClosed
 drawOpened
 lightOn
 doorOpened
 panelClosed
end

resetEvents
 doorOpened
end

commands
 unlockPanel
 ...
External DSL                      Internal DSL
events                            event :doorClosed
 doorClosed            ...
External DSL                      Internal DSL
events                            event :doorClosed
 doorClosed            ...
On top of external DSLs
no compromises
On top of external DSLs
no compromises
domain-specific static analysis
On top of external DSLs
no compromises
domain-specific static analysis
graphical views
On top of external DSLs
no compromises
domain-specific static analysis
graphical views
closed scope
Implementing an
external DSL
is
complicated
Why not using a DSL ...




... to develop DSLs?
Statemachine :
	 'events'
	 	 (events+=Event)+
	 'end'
	 'resetEvents'
	 	 (resetEvents+=[Event])+
	 'end'
	 'commands'
	 ...
Statemachine :
	 'events'
	 	 (events+=Event)+
	 'end'
	 'resetEvents'
                                        starts with...
Statemachine :
	 'events'
	 	 (events+=Event)+
	 'end'
	 'resetEvents'                            followed by at least one...
Statemachine :
	 'events'
	 	 (events+=Event)+
	 'end'
	 'resetEvents'
	 	 (resetEvents+=[Event])+
	 'end'
	 'commands'
	 ...
Statemachine :
	 'events'
	 	 (events+=Event)+
	 'end'
	 'resetEvents'
	 	 (resetEvents+=[Event])+
	 'end'
	 'commands'
	 ...
Statemachine :
	 'events'
	 	 (events+=Event)+
	 'end'
	 'resetEvents'
	 	 (resetEvents+=[Event])+
	 'end'
	 'commands'
	 ...
Statemachine :
	 'events'
	 	 (events+=Event)+
	 'end'
	 'resetEvents'
	 	 (resetEvents+=[Event])+
	 'end'
	 'commands'
	 ...
Statemachine :
	 'events'
	 	 (events+=Event)+
	 'end'
	 'resetEvents'
	 	 (resetEvents+=[Event])+
	 'end'
	 'commands'
	 ...
This was the example DSL
       implemented in



So what do we get from such a
         description?
Antlr based Parser
Antlr based Parser




Eclipse based Editor
Antlr based Parser




                            Eclipse based Editor
                                          Statemac...
Demo
oaw.itemis.com
    Thank you very much!
the eclipse distro can be downloaded from

http://oaw.itemis.com
Xtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
Upcoming SlideShare
Loading in …5
×

Xtext @ Profict Summer Camp

1,320 views
1,231 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,320
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
33
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Xtext @ Profict Summer Camp

  1. 1. Domain-Specific Languages with Sven Efftinge copyright 2008 by itemis AG
  2. 2. Kiel, Germany
  3. 3. Jan Peter Dennis
  4. 4. “... won’t talk about model-driven stuff”
  5. 5. You’re lucky!
  6. 6. No UML!
  7. 7. No MDA! No meta meta meta meta ...
  8. 8. Hands-on a concrete example taken from Martin Fowler’s upcoming Book on DSLs
  9. 9. You’re working for a company specialized on systems for secret compartments
  10. 10. Your customer: Mrs. H she likes secrets
  11. 11. To open the secret compartment, she has to
  12. 12. To open the secret compartment, she has to close the door,
  13. 13. To open the secret compartment, she has to close the door, open the second draw in her chest,
  14. 14. To open the secret compartment, she has to close the door, open the second draw in her chest, turn her bedside light on.
  15. 15. events doorClosed drawOpened lightOn doorOpened panelClosed end resetEvents doorOpened end commands unlockPanel lockPanel lockDoor unlockDoor end state idle actions {unlockDoor lockPanel} doorClosed => active end state active drawOpened => waitingForLight lightOn => waitingForDraw end state waitingForLight lightOn => unlockedPanel end state waitingForDraw drawOpened => unlockedPanel end state unlockedPanel actions {unlockPanel lockDoor} panelClosed => idle end
  16. 16. External DSL Internal DSL events event :doorClosed doorClosed event :drawOpened drawOpened event :lightOn lightOn doorOpened event :doorOpened panelClosed event :panelClosed end command :unlockPanel resetEvents command :lockPanel doorOpened end command :lockDoor command :unlockDoor commands unlockPanel resetEvents :doorOpened lockPanel lockDoor unlockDoor state :idle do end actions :unlockDoor, :lockPanel transitions :doorClosed => :active state idle end actions {unlockDoor lockPanel} doorClosed => active state :active do end transitions :drawOpened => :waitingForLight, state active :lightOn => :waitingForDraw drawOpened => waitingForLight end lightOn => waitingForDraw end state :waitingForLight do state waitingForLight transitions :lightOn => :unlockedPanel lightOn => unlockedPanel end end state :waitingForDraw do state waitingForDraw transitions :drawOpened => :unlockedPanel drawOpened => unlockedPanel end end state unlockedPanel state :unlockedPanel do actions {unlockPanel lockDoor} actions :unlockPanel, :lockDoor panelClosed => idle transitions :panelClosed => :idle end end
  17. 17. External DSL Internal DSL events event :doorClosed doorClosed event :drawOpened drawOpened event :lightOn lightOn doorOpened event :doorOpened panelClosed event :panelClosed end command :unlockPanel resetEvents command :lockPanel doorOpened end command :lockDoor command :unlockDoor commands unlockPanel resetEvents :doorOpened lockPanel lockDoor unlockDoor state :idle do end actions :unlockDoor, :lockPanel transitions :doorClosed => :active state idle end actions {unlockDoor lockPanel} doorClosed => active state :active do end transitions :drawOpened => :waitingForLight, state active :lightOn => :waitingForDraw drawOpened => waitingForLight end lightOn => waitingForDraw end state :waitingForLight do state waitingForLight transitions :lightOn => :unlockedPanel lightOn => unlockedPanel end end state :waitingForDraw do state waitingForDraw transitions :drawOpened => :unlockedPanel drawOpened => unlockedPanel end end state unlockedPanel state :unlockedPanel do actions {unlockPanel lockDoor} actions :unlockPanel, :lockDoor panelClosed => idle transitions :panelClosed => :idle end end
  18. 18. On top of external DSLs no compromises
  19. 19. On top of external DSLs no compromises domain-specific static analysis
  20. 20. On top of external DSLs no compromises domain-specific static analysis graphical views
  21. 21. On top of external DSLs no compromises domain-specific static analysis graphical views closed scope
  22. 22. Implementing an external DSL is complicated
  23. 23. Why not using a DSL ... ... to develop DSLs?
  24. 24. Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+; Event : name=ID; Command : name=ID; State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end'; Transition : event=[Event] '=>' state=[State];
  25. 25. Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' starts with keyword ‘events’ (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+; Event : name=ID; Command : name=ID; State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end'; Transition : event=[Event] '=>' state=[State];
  26. 26. Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' followed by at least one (resetEvents+=[Event])+ 'end' definition of Event 'commands' (commands+=Command)+ 'end' (states+=State)+; Event : name=ID; which is defined here and Command : name=ID; consists of just one identifier (ID) State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end'; Transition : event=[Event] '=>' state=[State];
  27. 27. Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+; this is a cross reference, Event : referencing Events name=ID; declared in the previous Command : name=ID; section. State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end'; Transition : event=[Event] '=>' state=[State];
  28. 28. Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+; Event : name=ID; commands are very Command : similar to events name=ID; State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end'; Transition : event=[Event] '=>' state=[State];
  29. 29. Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+; Event : States have a name (ID) name=ID; Command : name=ID; State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end'; Transition : event=[Event] '=>' state=[State];
  30. 30. Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+; Event : States have a name (ID) name=ID; Command : name=ID; optional action block State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end'; Transition : event=[Event] '=>' state=[State];
  31. 31. Statemachine : 'events' (events+=Event)+ 'end' 'resetEvents' (resetEvents+=[Event])+ 'end' 'commands' (commands+=Command)+ 'end' (states+=State)+; Event : States have a name (ID) name=ID; Command : name=ID; optional action block State : 'state' name=ID ('actions' '{' (actions+=[Command])+ '}')? (transitions+=Transition)* 'end'; Transition : any number of Transitions event=[Event] '=>' state=[State];
  32. 32. This was the example DSL implemented in So what do we get from such a description?
  33. 33. Antlr based Parser
  34. 34. Antlr based Parser Eclipse based Editor
  35. 35. Antlr based Parser Eclipse based Editor Statemachine commands * events * resetStates * states Command State Event name:String * name:String name:String actions state event EMF based Semantic Model * Transition
  36. 36. Demo
  37. 37. oaw.itemis.com Thank you very much! the eclipse distro can be downloaded from http://oaw.itemis.com

×