object grammars
play

Object Grammars Compositional & Bidirectional Mapping Between - PowerPoint PPT Presentation

Object Grammars Compositional & Bidirectional Mapping Between Text and Graphs Tijs van der Storm , William R. Cook, Alex Loh Monday, October 1, 12 http://www.enso-lang.org/ Monday, October 1, 12 Models Monday, October 1, 12 Text to


  1. Object Grammars Compositional & Bidirectional Mapping Between Text and Graphs Tijs van der Storm , William R. Cook, Alex Loh Monday, October 1, 12

  2. http://www.enso-lang.org/ Monday, October 1, 12

  3. Models Monday, October 1, 12

  4. Text to objects and back :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed Object Grammar name: "Opened" name: "Closed" name: "Locked" state Closed to from to to from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" close lock Opened Closed Locked unlock open Monday, October 1, 12

  5. Object Grammars • Interleave grammar with data binding • object construction • field assignment • predicates • Bind to paths in to create cross references • Formatting hints to guide pretty printing Monday, October 1, 12

  6. Points P ::= [Point] "(" x: int "," y: int ")" Monday, October 1, 12

  7. Points Constructor P ::= [Point] "(" x: int "," y: int ")" Monday, October 1, 12

  8. Points Constructor Field binding P ::= [Point] "(" x: int "," y: int ")" Monday, October 1, 12

  9. Points Constructor Field binding Built-in primitives P ::= [Point] "(" x: int "," y: int ")" Monday, October 1, 12

  10. Points Constructor Field binding Built-in primitives P ::= [Point] "(" x: int "," y: int ")" The schema class Point x: int y: int Monday, October 1, 12

  11. Points Constructor Field binding Built-in primitives P ::= [Point] "(" x: int "," y: int ")" The schema class Point x: int y: int Monday, October 1, 12

  12. Points Constructor Field binding Built-in primitives P ::= [Point] "(" x: int "," y: int ")" The schema class Point x: int y: int Monday, October 1, 12

  13. Points Constructor Field binding Built-in primitives P ::= [Point] "(" x: int "," y: int ")" The schema class Point x: int y: int Monday, October 1, 12

  14. Expressions Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp | [Binary] lhs:Exp op:"*" rhs:Exp [Const] value: int | | "(" Exp ")" class Exp class Binary < Exp op: str lhs: Exp rhs: Exp class Const < Exp value: int Monday, October 1, 12

  15. Expressions Both + and * become Binary objects Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp | [Binary] lhs:Exp op:"*" rhs:Exp [Const] value: int | | "(" Exp ")" class Exp class Binary < Exp op: str lhs: Exp rhs: Exp class Const < Exp value: int Monday, October 1, 12

  16. Expressions Both + and * become Binary objects Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp | [Binary] lhs:Exp op:"*" rhs:Exp [Const] value: int | | "(" Exp ")" class Exp class Binary < Exp Parentheses don’t op: str lhs: Exp introduce objects rhs: Exp class Const < Exp value: int Monday, October 1, 12

  17. Expressions Refactored grammar for disambiguation Term ::= [Binary] lhs:Term op:"+" rhs:Fact | Fact Fact ::= [Binary] lhs:Fact op:"*" rhs:Prim | Prim class Exp Prim ::= [Const] value: int class Binary < Exp op: str | "(" Term ")" lhs: Exp rhs: Exp class Const < Exp value: int Monday, October 1, 12

  18. State machines start Opened :Machine start machine state Opened states states states on close go Closed :State :State :State name: "Opened" name: "Closed" name: "Locked" state Closed to from to to from from to from on open go Opened in out in out :Transition :Transition on lock go Locked event: "open" event: "unlock" out in state Locked : Transition : Transition in out event: "lock" event: "close" on unlock go Closed close lock Opened Closed Locked unlock open Monday, October 1, 12

  19. The object grammar M ::= [Machine] "start" \start:</states[ it ]> states:S* S ::= [State] "state" name: sym out:T* T ::= [Transition] "on" event: sym "go" to:</states[ it ]> Monday, October 1, 12

  20. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

  21. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

  22. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

  23. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

  24. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

  25. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

  26. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

  27. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

  28. Creating the spine :Machine start start Opened machine states states states state Opened :State :State :State on close go Closed name: "Opened" name: "Closed" name: "Locked" to from to to state Closed from from to from in out in out on open go Opened :Transition :Transition on lock go Locked event: "open" event: "unlock" out state Locked in : Transition : Transition on unlock go Closed in out event: "lock" event: "close" Monday, October 1, 12

Recommend


More recommend