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 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
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
Points P ::= [Point] "(" x: int "," y: int ")" Monday, October 1, 12
Points Constructor P ::= [Point] "(" x: int "," y: int ")" Monday, October 1, 12
Points Constructor Field binding P ::= [Point] "(" x: int "," y: int ")" Monday, October 1, 12
Points Constructor Field binding Built-in primitives P ::= [Point] "(" x: int "," y: int ")" Monday, October 1, 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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