Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Xtext @ Profict Summer Camp

1,554 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

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

×