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

Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Object GrammarsCompositional & Bidirectional Mapping Between Text and Graphs

Tijs van der Storm, William R. Cook, Alex Loh

Monday, October 1, 12

Page 2: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

http://www.enso-lang.org/

Monday, October 1, 12

Page 3: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Models

Monday, October 1, 12

Page 4: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Text to objects and back

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Object Grammar

Monday, October 1, 12

Page 5: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

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

Page 6: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Points

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Monday, October 1, 12

Page 7: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Points

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Constructor

Monday, October 1, 12

Page 8: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Points

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Constructor Field binding

Monday, October 1, 12

Page 9: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Points

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Constructor Field binding Built-in primitives

Monday, October 1, 12

Page 10: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Points

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Constructor Field binding Built-in primitives

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

The schema

Monday, October 1, 12

Page 11: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Points

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Constructor Field binding Built-in primitives

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

The schema

Monday, October 1, 12

Page 12: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Points

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Constructor Field binding Built-in primitives

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

The schema

Monday, October 1, 12

Page 13: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Points

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Constructor Field binding Built-in primitives

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

The schema

Monday, October 1, 12

Page 14: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Expressions

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

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

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

This grammar is not very useful, because it is ambiguous. To resolve this ambiguity, weuse the standard technique for encoding precedence and associativity using additionalnon-terminals.

Term ::= [Binary] lhs:Term op:"+" rhs:Fact | Fact

Fact ::= [Binary] lhs:Fact op:"*" rhs:Prim | Prim

Prim ::= [Const] value:int | "(" Term ")"

This grammar refactoring is independent of the schema for expressions; the additionalnon-terminals (Term, Fact, Prim) do not have corresponding classes. Object grammarsallow ambiguous grammars: as long as individual input strings are not ambiguous therewill be no error. Thus the original version can only parse fully parenthesized expressions,while the second version handles standard expression notation.

During formatting, the alternatives are searched in order until a matching case isfound. For example, to format Binary(Binary(3,"+",5),"*",7) as a Term, the top-levelstructure is a binary object with a * operator. The Term case does not apply, because theoperator does not match, so it formats the second alternative, Fact. The first alternativeof Fact matches, and the left hand side Binary(3,"+",5) must be formatted as a Fact.The first case for Fact does not match, so it is formatted as a Prim. The first case for Primalso does not match, so parentheses are added and the expression is formatted as a Term.The net effect is that the necessary parentheses are added automatically, to format as(3+5)*7.

2.3 Collections

Object Grammars support regular symbols to automatically map collections of values.For example, consider this grammar for function calls:

C ::= [Call] fun:id "(" args:Exp* @"," ")"

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

Monday, October 1, 12

Page 15: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Expressions

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Both + and * become Binary objects

class Exp

class Binary < Exp

op: str

lhs: Exp

rhs: Exp

class Const < Exp

value: int

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

This grammar is not very useful, because it is ambiguous. To resolve this ambiguity, weuse the standard technique for encoding precedence and associativity using additionalnon-terminals.

Term ::= [Binary] lhs:Term op:"+" rhs:Fact | Fact

Fact ::= [Binary] lhs:Fact op:"*" rhs:Prim | Prim

Prim ::= [Const] value:int | "(" Term ")"

This grammar refactoring is independent of the schema for expressions; the additionalnon-terminals (Term, Fact, Prim) do not have corresponding classes. Object grammarsallow ambiguous grammars: as long as individual input strings are not ambiguous therewill be no error. Thus the original version can only parse fully parenthesized expressions,while the second version handles standard expression notation.

During formatting, the alternatives are searched in order until a matching case isfound. For example, to format Binary(Binary(3,"+",5),"*",7) as a Term, the top-levelstructure is a binary object with a * operator. The Term case does not apply, because theoperator does not match, so it formats the second alternative, Fact. The first alternativeof Fact matches, and the left hand side Binary(3,"+",5) must be formatted as a Fact.The first case for Fact does not match, so it is formatted as a Prim. The first case for Primalso does not match, so parentheses are added and the expression is formatted as a Term.The net effect is that the necessary parentheses are added automatically, to format as(3+5)*7.

2.3 Collections

Object Grammars support regular symbols to automatically map collections of values.For example, consider this grammar for function calls:

C ::= [Call] fun:id "(" args:Exp* @"," ")"

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

Monday, October 1, 12

Page 16: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Expressions

syntax and object graphs. The syntactic structure is specified using a form of ExtendedBackus-Naur Form (EBNF) [41], which integrated regular iteration and optional symbolsinto BNF. Object Grammar extend BNF with constructs to declaratively construct objects,bind values to fields, create cross links and evaluate predicates.

2.1 Construction and field binding

The most fundamental feature of Object Grammars is the ability to declaratively constructobjects and assign their fields with values taken from the input stream. The followingexample defines a production rule named P that parses the standard notation (x, y) forcartesian points and creates a corresponding Point object.

P ::= [Point] "(" x:int "," y:int ")"

The production rule begins with a constructor [Point] which indicates that the rulecreates a Point object. The literals "(", "," and ")" match the literal text in the input.The field binding expressions x:int and y:int assign the fields x and y of the new pointto integers extracted from the input steam. The classes and fields used in a grammarmust be defined in a schema [26]. For example, the schema for points is:

class Point x: int y: int

Any pattern in a grammar can be refactored to introduce new non-terminals withoutany effect on the result of parsing For example, the above grammar can be rewrittenequivalently as

P ::= [Point] "(" XY ")"

XY ::= x:int "," y:int

The XY production can be reused to set the x and y fields of any kind of object, not justpoints.

The Object Grammars given above can also be used to format points into textualform. The constructor acts as a guard that specifies that points should be rendered. Theliteral symbols are copied directly to the output. The field assignments are treated asselections that format the x and y fields of the point as integers.

2.2 Alternatives and Object-Valued Fields

Each alternative in a production can construct an appropriate object. The followingexample constructs either a constant, or one of two different kinds of Binary objects.The last alternative does not construct an object, but instead returns the value created bythe nested Exp.

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

Both + and * become Binary objects

Parentheses don’t introduce objects

class Exp

class Binary < Exp

op: str

lhs: Exp

rhs: Exp

class Const < Exp

value: int

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

This grammar is not very useful, because it is ambiguous. To resolve this ambiguity, weuse the standard technique for encoding precedence and associativity using additionalnon-terminals.

Term ::= [Binary] lhs:Term op:"+" rhs:Fact | Fact

Fact ::= [Binary] lhs:Fact op:"*" rhs:Prim | Prim

Prim ::= [Const] value:int | "(" Term ")"

This grammar refactoring is independent of the schema for expressions; the additionalnon-terminals (Term, Fact, Prim) do not have corresponding classes. Object grammarsallow ambiguous grammars: as long as individual input strings are not ambiguous therewill be no error. Thus the original version can only parse fully parenthesized expressions,while the second version handles standard expression notation.

During formatting, the alternatives are searched in order until a matching case isfound. For example, to format Binary(Binary(3,"+",5),"*",7) as a Term, the top-levelstructure is a binary object with a * operator. The Term case does not apply, because theoperator does not match, so it formats the second alternative, Fact. The first alternativeof Fact matches, and the left hand side Binary(3,"+",5) must be formatted as a Fact.The first case for Fact does not match, so it is formatted as a Prim. The first case for Primalso does not match, so parentheses are added and the expression is formatted as a Term.The net effect is that the necessary parentheses are added automatically, to format as(3+5)*7.

2.3 Collections

Object Grammars support regular symbols to automatically map collections of values.For example, consider this grammar for function calls:

C ::= [Call] fun:id "(" args:Exp* @"," ")"

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

Monday, October 1, 12

Page 17: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

class Exp

class Binary < Exp

op: str

lhs: Exp

rhs: Exp

class Const < Exp

value: int

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

This grammar is not very useful, because it is ambiguous. To resolve this ambiguity, weuse the standard technique for encoding precedence and associativity using additionalnon-terminals.

Term ::= [Binary] lhs:Term op:"+" rhs:Fact | Fact

Fact ::= [Binary] lhs:Fact op:"*" rhs:Prim | Prim

Prim ::= [Const] value:int | "(" Term ")"

This grammar refactoring is independent of the schema for expressions; the additionalnon-terminals (Term, Fact, Prim) do not have corresponding classes. Object grammarsallow ambiguous grammars: as long as individual input strings are not ambiguous therewill be no error. Thus the original version can only parse fully parenthesized expressions,while the second version handles standard expression notation.

During formatting, the alternatives are searched in order until a matching case isfound. For example, to format Binary(Binary(3,"+",5),"*",7) as a Term, the top-levelstructure is a binary object with a * operator. The Term case does not apply, because theoperator does not match, so it formats the second alternative, Fact. The first alternativeof Fact matches, and the left hand side Binary(3,"+",5) must be formatted as a Fact.The first case for Fact does not match, so it is formatted as a Prim. The first case for Primalso does not match, so parentheses are added and the expression is formatted as a Term.The net effect is that the necessary parentheses are added automatically, to format as(3+5)*7.

2.3 Collections

Object Grammars support regular symbols to automatically map collections of values.For example, consider this grammar for function calls:

C ::= [Call] fun:id "(" args:Exp* @"," ")"

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

class Exp

class Binary < Exp

op: str

lhs: Exp

rhs: Exp

class Const < Exp

value: int

Exp ::= [Binary] lhs:Exp op:"+" rhs:Exp

| [Binary] lhs:Exp op:"*" rhs:Exp

| [Const] value:int

| "(" Exp ")"

This grammar is not very useful, because it is ambiguous. To resolve this ambiguity, weuse the standard technique for encoding precedence and associativity using additionalnon-terminals.

Term ::= [Binary] lhs:Term op:"+" rhs:Fact

| Fact

Fact ::= [Binary] lhs:Fact op:"*" rhs:Prim

| Prim

Prim ::= [Const] value:int

| "(" Term ")"

This grammar refactoring is independent of the schema for expressions; the additionalnon-terminals (Term, Fact, Prim) do not have corresponding classes. Object grammarsallow ambiguous grammars: as long as individual input strings are not ambiguous therewill be no error. Thus the original version can only parse fully parenthesized expressions,while the second version handles standard expression notation.

During formatting, the alternatives are searched in order until a matching case isfound. For example, to format Binary(Binary(3,"+",5),"*",7) as a Term, the top-levelstructure is a binary object with a * operator. The Term case does not apply, because theoperator does not match, so it formats the second alternative, Fact. The first alternativeof Fact matches, and the left hand side Binary(3,"+",5) must be formatted as a Fact.The first case for Fact does not match, so it is formatted as a Prim. The first case for Primalso does not match, so parentheses are added and the expression is formatted as a Term.The net effect is that the necessary parentheses are added automatically, to format as(3+5)*7.

2.3 Collections

Object Grammars support regular symbols to automatically map collections of values.For example, consider this grammar for function calls:

C ::= [Call] fun:id "(" args:Exp* @"," ")"

Refactored grammar for disambiguation

Expressions

Monday, October 1, 12

Page 18: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

State machinesOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 19: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

The object grammar

start M

M ::= [Machine] "start" \start:</states[it]> states:S*

S ::= [State] "state" name:sym out:T*

T ::= [Transition] "on" event:sym "go" to:</states[it]>

Fig. 3. Object Grammar to parse state machines

When humans read the textual presentation in Fig. 1(b), they immediately resolve thenames in each transition to create a mental picture similar Fig. 1(a).

Figure 3 shows an Object Grammar for state machines5. It uses the reference</states[it]> to look up the start state of a machine and to find the the target state ofa transition. The path /states[it] starts at the root of the resulting object model, asindicated by the forward slash /. In this case the root is a Machine object, since M isthe start symbol of the grammar, and the M production creates a Machine. The path thennavigates into the field states of the machine (see Fig. 2), and uses the identifier fromthe input stream to index into the keyed collection of all states. The same path is used toresolve the to field of a transition to the target state.

Path ::= [Anchor] type:"."

| [Anchor] type:".."

|

[Sub] parent:Path? "/" name:sym Subscript?

Subscript

::= "[" key:Key "]"

Key ::= Path | [It] "it"

Fig. 4. Syntax of paths.

References and Paths In gen-eral, a reference <p> representsa lookup of an object using thepath p. Parsing a reference al-ways consumes a single identi-fier, which can be used as a keyfor indexing into keyed collec-tions. Binding a field to a refer-ence thus results in a cross-linkfrom the current object to the ref-erenced object.

The syntax of paths is given in Fig. 4. A path is anchored at the current object (.), atits parent (..), or at the root. In the context of an object a path can descend into a field bypost-fixing a path with / and the name of the field. If the field is a collection, a specificelement can be referenced by indexing in square brackets. The keyword it representsthe string-typed value of the identifier in the input stream that represents the referencename.

The grammar of schemas, given in Fig. 5, illustrates a more complex use of references.To lookup inverse fields, it is necessary to look for the field within the class that is thetype of the field. For example, in the state machine schema in Fig. 1(b), the field from inTransition has type State and its inverse is the out field of State. The path for the typeis type:</types[it]>, while the path for the inverse is inverse:<./type/fields[it]>,

5 The field label start is escaped using \ because start is a keyword in the grammar of grammars;cf. Section 2.7.

Monday, October 1, 12

Page 20: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 21: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 22: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 23: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 24: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 25: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 26: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 27: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 28: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Creating the spineOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 29: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened

Closed

Locked

close

open

unlock

lock

(a)

startOpened

stateOpened

onclosego

Closed

stateClosed

onopen

goOpened

onlock

goLocked

stateLocked

onunlock

goClosed

(b)

:Mac

hine

nam

e: "O

pene

d"

:Sta

te

nam

e: "C

lose

d"

:Sta

te

nam

e: "L

ocke

d"

:Sta

te

even

t: "c

lose

"

: Tra

nsiti

on

even

t: "o

pen"

:Tra

nsiti

on

even

t: "lo

ck"

: Tra

nsiti

on

even

t: "u

nloc

k"

:Tra

nsiti

on

from

out

in

to in

to

in

from

out

from

stat

esst

ates

out

from

to

stat

es

mac

hine

out

in

to

star

t

(c)

Fig.

1.(a

) Exa

mpl

est

ate

mac

hine

ingr

aphi

cal n

otat

ion,

(b) t

hest

ate

mac

hine

inte

xtua

l not

atio

n,an

d(c

) the

inte

rnal

repr

esen

tatio

nof

the

stat

em

achi

nein

obje

ctdi

agra

mno

tatio

n

The

regu

lar r

epet

ition

gram

mar

oper

ator

*m

aybe

optio

nally

follo

wed

bya

sepa

rato

rus

ing@,

whi

chin

this

case

isa

com

ma.

Theargs

field

ofth

eCall

clas

s is a

ssig

ned

obje

cts

crea

ted

byze

ro-o

r-m

ore

occu

rren

ces

ofExp.

Aco

llect

ion

field

can

also

beex

plic

itly

boun

dm

ultip

letim

es, r

athe

r tha

nus

ing

the*

oper

ator

. For

exam

ple,

args:Exp*

coul

dbe

repl

aced

byArgs?

whe

reArgs

::=args:Exp

(","Args)?

.Fo

r for

mat

ting,

the

regu

lar o

pera

tors

*an

d+

prov

ide

addi

tiona

l sem

antic

s,al

low

ing

the

form

atte

r to

perf

orm

inte

llige

ntgr

oupi

ngan

din

dent

atio

n.A

repe

ated

grou

pis

eith

erfo

rmat

ted

onon

elin

e,or

else

itis

inde

nted

and

brok

enin

tom

ultip

lelin

esif

itis

too

long

.

2.4

Ref

eren

ceR

esol

utio

n

Inor

der t

oex

plai

npa

th-b

ased

refe

renc

ere

solu

tion

inO

bjec

t Gra

mm

ars,

itis

inst

ruct

ive

toin

trodu

cea

slig

htly

mor

eel

abor

ate

exam

ple.

Con

side

r asm

all D

SLfo

r mod

elin

gst

ate

mac

hine

s.Fi

gure

1di

spla

ysth

ree

repr

esen

tatio

nsof

asi

mpl

est

ate

mac

hine

repr

esen

ting

ado

orth

atca

nbe

open

ed, c

lose

d,an

dlo

cked

. Fig

ure

1(a)

show

sth

est

ate

mac

hine

ingr

aphi

cal n

otat

ion.

The

sam

est

ate

mac

hine

isre

nder

edte

xtua

llyin

Fig.

1(b)

. Int

erna

lly,

the

mac

hine

itsel

f,its

stat

esan

dth

etra

nsiti

ons

are

all r

epre

sent

edex

plic

itly

asob

ject

s.Th

isis

illus

trate

din

the

obje

ctdi

agra

mgi

ven

inFi

g.1(

c).

The

obje

ctdi

agra

mco

nfor

ms

toth

eSt

ate

Mac

hine

sche

ma

give

nin

Fig.

2.Th

esc

hem

aco

nsis

tsof

alis

t of n

amed

clas

ses,

each

havi

nga

list o

f fiel

dsde

fined

bya

nam

e,a

type

, and

som

eop

tiona

l mod

ifier

s.Fo

r exa

mpl

e,th

eMachine

clas

sha

sa

field

nam

edstates

whi

chis

ase

t of S

tate

obje

cts.

The*

afte

r the

type

nam

eis

am

odifi

erth

atm

arks

the

field

asm

any-

valu

ed. T

he#

anno

tatio

nm

arks

afie

ldas

apr

imar

yke

y,as

isth

eca

sefo

r the

name

field

ofth

eSt

ate

clas

s.A

sa

resu

lt,st

ate

nam

esm

ust b

eun

ique

and

thestates

field

ofMachine

can

bein

dexe

dby

nam

e.Th

e/

anno

tatio

naf

ter t

hemachine

field

indi

cate

s tha

t the

machine

andstates

are

inve

rses

, as a

refrom

/out

andto

/in.

The!

Monday, October 1, 12

Page 30: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened

Closed

Locked

close

open

unlock

lock

(a)

startOpened

stateOpened

onclosego

Closed

stateClosed

onopen

goOpened

onlock

goLocked

stateLocked

onunlock

goClosed

(b)

:Mac

hine

nam

e: "O

pene

d"

:Sta

te

nam

e: "C

lose

d"

:Sta

te

nam

e: "L

ocke

d"

:Sta

te

even

t: "c

lose

"

: Tra

nsiti

on

even

t: "o

pen"

:Tra

nsiti

on

even

t: "lo

ck"

: Tra

nsiti

on

even

t: "u

nloc

k"

:Tra

nsiti

on

from

out

in

to in

to

in

from

out

from

stat

esst

ates

out

from

to

stat

es

mac

hine

out

in

to

star

t

(c)

Fig.

1.(a

) Exa

mpl

est

ate

mac

hine

ingr

aphi

cal n

otat

ion,

(b) t

hest

ate

mac

hine

inte

xtua

l not

atio

n,an

d(c

) the

inte

rnal

repr

esen

tatio

nof

the

stat

em

achi

nein

obje

ctdi

agra

mno

tatio

n

The

regu

lar r

epet

ition

gram

mar

oper

ator

*m

aybe

optio

nally

follo

wed

bya

sepa

rato

rus

ing@,

whi

chin

this

case

isa

com

ma.

Theargs

field

ofth

eCall

clas

s is a

ssig

ned

obje

cts

crea

ted

byze

ro-o

r-m

ore

occu

rren

ces

ofExp.

Aco

llect

ion

field

can

also

beex

plic

itly

boun

dm

ultip

letim

es, r

athe

r tha

nus

ing

the*

oper

ator

. For

exam

ple,

args:Exp*

coul

dbe

repl

aced

byArgs?

whe

reArgs

::=args:Exp

(","Args)?

.Fo

r for

mat

ting,

the

regu

lar o

pera

tors

*an

d+

prov

ide

addi

tiona

l sem

antic

s,al

low

ing

the

form

atte

r to

perf

orm

inte

llige

ntgr

oupi

ngan

din

dent

atio

n.A

repe

ated

grou

pis

eith

erfo

rmat

ted

onon

elin

e,or

else

itis

inde

nted

and

brok

enin

tom

ultip

lelin

esif

itis

too

long

.

2.4

Ref

eren

ceR

esol

utio

n

Inor

der t

oex

plai

npa

th-b

ased

refe

renc

ere

solu

tion

inO

bjec

t Gra

mm

ars,

itis

inst

ruct

ive

toin

trodu

cea

slig

htly

mor

eel

abor

ate

exam

ple.

Con

side

r asm

all D

SLfo

r mod

elin

gst

ate

mac

hine

s.Fi

gure

1di

spla

ysth

ree

repr

esen

tatio

nsof

asi

mpl

est

ate

mac

hine

repr

esen

ting

ado

orth

atca

nbe

open

ed, c

lose

d,an

dlo

cked

. Fig

ure

1(a)

show

sth

est

ate

mac

hine

ingr

aphi

cal n

otat

ion.

The

sam

est

ate

mac

hine

isre

nder

edte

xtua

llyin

Fig.

1(b)

. Int

erna

lly,

the

mac

hine

itsel

f,its

stat

esan

dth

etra

nsiti

ons

are

all r

epre

sent

edex

plic

itly

asob

ject

s.Th

isis

illus

trate

din

the

obje

ctdi

agra

mgi

ven

inFi

g.1(

c).

The

obje

ctdi

agra

mco

nfor

ms

toth

eSt

ate

Mac

hine

sche

ma

give

nin

Fig.

2.Th

esc

hem

aco

nsis

tsof

alis

t of n

amed

clas

ses,

each

havi

nga

list o

f fiel

dsde

fined

bya

nam

e,a

type

, and

som

eop

tiona

l mod

ifier

s.Fo

r exa

mpl

e,th

eMachine

clas

sha

sa

field

nam

edstates

whi

chis

ase

t of S

tate

obje

cts.

The*

afte

r the

type

nam

eis

am

odifi

erth

atm

arks

the

field

asm

any-

valu

ed. T

he#

anno

tatio

nm

arks

afie

ldas

apr

imar

yke

y,as

isth

eca

sefo

r the

name

field

ofth

eSt

ate

clas

s.A

sa

resu

lt,st

ate

nam

esm

ust b

eun

ique

and

thestates

field

ofMachine

can

bein

dexe

dby

nam

e.Th

e/

anno

tatio

naf

ter t

hemachine

field

indi

cate

s tha

t the

machine

andstates

are

inve

rses

, as a

refrom

/out

andto

/in.

The!

Monday, October 1, 12

Page 31: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened

Closed

Locked

close

open

unlock

lock

(a)

startOpened

stateOpened

onclosego

Closed

stateClosed

onopen

goOpened

onlock

goLocked

stateLocked

onunlock

goClosed

(b)

:Mac

hine

nam

e: "O

pene

d"

:Sta

te

nam

e: "C

lose

d"

:Sta

te

nam

e: "L

ocke

d"

:Sta

te

even

t: "c

lose

"

: Tra

nsiti

on

even

t: "o

pen"

:Tra

nsiti

on

even

t: "lo

ck"

: Tra

nsiti

on

even

t: "u

nloc

k"

:Tra

nsiti

on

from

out

in

to in

to

in

from

out

from

stat

esst

ates

out

from

to

stat

es

mac

hine

out

in

to

star

t

(c)

Fig.

1.(a

) Exa

mpl

est

ate

mac

hine

ingr

aphi

cal n

otat

ion,

(b) t

hest

ate

mac

hine

inte

xtua

l not

atio

n,an

d(c

) the

inte

rnal

repr

esen

tatio

nof

the

stat

em

achi

nein

obje

ctdi

agra

mno

tatio

n

The

regu

lar r

epet

ition

gram

mar

oper

ator

*m

aybe

optio

nally

follo

wed

bya

sepa

rato

rus

ing@,

whi

chin

this

case

isa

com

ma.

Theargs

field

ofth

eCall

clas

s is a

ssig

ned

obje

cts

crea

ted

byze

ro-o

r-m

ore

occu

rren

ces

ofExp.

Aco

llect

ion

field

can

also

beex

plic

itly

boun

dm

ultip

letim

es, r

athe

r tha

nus

ing

the*

oper

ator

. For

exam

ple,

args:Exp*

coul

dbe

repl

aced

byArgs?

whe

reArgs

::=args:Exp

(","Args)?

.Fo

r for

mat

ting,

the

regu

lar o

pera

tors

*an

d+

prov

ide

addi

tiona

l sem

antic

s,al

low

ing

the

form

atte

r to

perf

orm

inte

llige

ntgr

oupi

ngan

din

dent

atio

n.A

repe

ated

grou

pis

eith

erfo

rmat

ted

onon

elin

e,or

else

itis

inde

nted

and

brok

enin

tom

ultip

lelin

esif

itis

too

long

.

2.4

Ref

eren

ceR

esol

utio

n

Inor

der t

oex

plai

npa

th-b

ased

refe

renc

ere

solu

tion

inO

bjec

t Gra

mm

ars,

itis

inst

ruct

ive

toin

trodu

cea

slig

htly

mor

eel

abor

ate

exam

ple.

Con

side

r asm

all D

SLfo

r mod

elin

gst

ate

mac

hine

s.Fi

gure

1di

spla

ysth

ree

repr

esen

tatio

nsof

asi

mpl

est

ate

mac

hine

repr

esen

ting

ado

orth

atca

nbe

open

ed, c

lose

d,an

dlo

cked

. Fig

ure

1(a)

show

sth

est

ate

mac

hine

ingr

aphi

cal n

otat

ion.

The

sam

est

ate

mac

hine

isre

nder

edte

xtua

llyin

Fig.

1(b)

. Int

erna

lly,

the

mac

hine

itsel

f,its

stat

esan

dth

etra

nsiti

ons

are

all r

epre

sent

edex

plic

itly

asob

ject

s.Th

isis

illus

trate

din

the

obje

ctdi

agra

mgi

ven

inFi

g.1(

c).

The

obje

ctdi

agra

mco

nfor

ms

toth

eSt

ate

Mac

hine

sche

ma

give

nin

Fig.

2.Th

esc

hem

aco

nsis

tsof

alis

t of n

amed

clas

ses,

each

havi

nga

list o

f fiel

dsde

fined

bya

nam

e,a

type

, and

som

eop

tiona

l mod

ifier

s.Fo

r exa

mpl

e,th

eMachine

clas

sha

sa

field

nam

edstates

whi

chis

ase

t of S

tate

obje

cts.

The*

afte

r the

type

nam

eis

am

odifi

erth

atm

arks

the

field

asm

any-

valu

ed. T

he#

anno

tatio

nm

arks

afie

ldas

apr

imar

yke

y,as

isth

eca

sefo

r the

name

field

ofth

eSt

ate

clas

s.A

sa

resu

lt,st

ate

nam

esm

ust b

eun

ique

and

thestates

field

ofMachine

can

bein

dexe

dby

nam

e.Th

e/

anno

tatio

naf

ter t

hemachine

field

indi

cate

s tha

t the

machine

andstates

are

inve

rses

, as a

refrom

/out

andto

/in.

The!

Monday, October 1, 12

Page 32: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened

Closed

Locked

close

open

unlock

lock

(a)

startOpened

stateOpened

onclosego

Closed

stateClosed

onopen

goOpened

onlock

goLocked

stateLocked

onunlock

goClosed

(b)

:Mac

hine

nam

e: "O

pene

d"

:Sta

te

nam

e: "C

lose

d"

:Sta

te

nam

e: "L

ocke

d"

:Sta

te

even

t: "c

lose

"

: Tra

nsiti

on

even

t: "o

pen"

:Tra

nsiti

on

even

t: "lo

ck"

: Tra

nsiti

on

even

t: "u

nloc

k"

:Tra

nsiti

on

from

out

in

to in

to

in

from

out

from

stat

esst

ates

out

from

to

stat

es

mac

hine

out

in

to

star

t

(c)

Fig.

1.(a

) Exa

mpl

est

ate

mac

hine

ingr

aphi

cal n

otat

ion,

(b) t

hest

ate

mac

hine

inte

xtua

l not

atio

n,an

d(c

) the

inte

rnal

repr

esen

tatio

nof

the

stat

em

achi

nein

obje

ctdi

agra

mno

tatio

n

The

regu

lar r

epet

ition

gram

mar

oper

ator

*m

aybe

optio

nally

follo

wed

bya

sepa

rato

rus

ing@,

whi

chin

this

case

isa

com

ma.

Theargs

field

ofth

eCall

clas

s is a

ssig

ned

obje

cts

crea

ted

byze

ro-o

r-m

ore

occu

rren

ces

ofExp.

Aco

llect

ion

field

can

also

beex

plic

itly

boun

dm

ultip

letim

es, r

athe

r tha

nus

ing

the*

oper

ator

. For

exam

ple,

args:Exp*

coul

dbe

repl

aced

byArgs?

whe

reArgs

::=args:Exp

(","Args)?

.Fo

r for

mat

ting,

the

regu

lar o

pera

tors

*an

d+

prov

ide

addi

tiona

l sem

antic

s,al

low

ing

the

form

atte

r to

perf

orm

inte

llige

ntgr

oupi

ngan

din

dent

atio

n.A

repe

ated

grou

pis

eith

erfo

rmat

ted

onon

elin

e,or

else

itis

inde

nted

and

brok

enin

tom

ultip

lelin

esif

itis

too

long

.

2.4

Ref

eren

ceR

esol

utio

n

Inor

der t

oex

plai

npa

th-b

ased

refe

renc

ere

solu

tion

inO

bjec

t Gra

mm

ars,

itis

inst

ruct

ive

toin

trodu

cea

slig

htly

mor

eel

abor

ate

exam

ple.

Con

side

r asm

all D

SLfo

r mod

elin

gst

ate

mac

hine

s.Fi

gure

1di

spla

ysth

ree

repr

esen

tatio

nsof

asi

mpl

est

ate

mac

hine

repr

esen

ting

ado

orth

atca

nbe

open

ed, c

lose

d,an

dlo

cked

. Fig

ure

1(a)

show

sth

est

ate

mac

hine

ingr

aphi

cal n

otat

ion.

The

sam

est

ate

mac

hine

isre

nder

edte

xtua

llyin

Fig.

1(b)

. Int

erna

lly,

the

mac

hine

itsel

f,its

stat

esan

dth

etra

nsiti

ons

are

all r

epre

sent

edex

plic

itly

asob

ject

s.Th

isis

illus

trate

din

the

obje

ctdi

agra

mgi

ven

inFi

g.1(

c).

The

obje

ctdi

agra

mco

nfor

ms

toth

eSt

ate

Mac

hine

sche

ma

give

nin

Fig.

2.Th

esc

hem

aco

nsis

tsof

alis

t of n

amed

clas

ses,

each

havi

nga

list o

f fiel

dsde

fined

bya

nam

e,a

type

, and

som

eop

tiona

l mod

ifier

s.Fo

r exa

mpl

e,th

eMachine

clas

sha

sa

field

nam

edstates

whi

chis

ase

t of S

tate

obje

cts.

The*

afte

r the

type

nam

eis

am

odifi

erth

atm

arks

the

field

asm

any-

valu

ed. T

he#

anno

tatio

nm

arks

afie

ldas

apr

imar

yke

y,as

isth

eca

sefo

r the

name

field

ofth

eSt

ate

clas

s.A

sa

resu

lt,st

ate

nam

esm

ust b

eun

ique

and

thestates

field

ofMachine

can

bein

dexe

dby

nam

e.Th

e/

anno

tatio

naf

ter t

hemachine

field

indi

cate

s tha

t the

machine

andstates

are

inve

rses

, as a

refrom

/out

andto

/in.

The!

Monday, October 1, 12

Page 33: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened

Closed

Locked

close

open

unlock

lock

(a)

startOpened

stateOpened

onclosego

Closed

stateClosed

onopen

goOpened

onlock

goLocked

stateLocked

onunlock

goClosed

(b)

:Mac

hine

nam

e: "O

pene

d"

:Sta

te

nam

e: "C

lose

d"

:Sta

te

nam

e: "L

ocke

d"

:Sta

te

even

t: "c

lose

"

: Tra

nsiti

on

even

t: "o

pen"

:Tra

nsiti

on

even

t: "lo

ck"

: Tra

nsiti

on

even

t: "u

nloc

k"

:Tra

nsiti

on

from

out

in

to in

to

in

from

out

from

stat

esst

ates

out

from

to

stat

es

mac

hine

out

in

to

star

t

(c)

Fig.

1.(a

) Exa

mpl

est

ate

mac

hine

ingr

aphi

cal n

otat

ion,

(b) t

hest

ate

mac

hine

inte

xtua

l not

atio

n,an

d(c

) the

inte

rnal

repr

esen

tatio

nof

the

stat

em

achi

nein

obje

ctdi

agra

mno

tatio

n

The

regu

lar r

epet

ition

gram

mar

oper

ator

*m

aybe

optio

nally

follo

wed

bya

sepa

rato

rus

ing@,

whi

chin

this

case

isa

com

ma.

Theargs

field

ofth

eCall

clas

s is a

ssig

ned

obje

cts

crea

ted

byze

ro-o

r-m

ore

occu

rren

ces

ofExp.

Aco

llect

ion

field

can

also

beex

plic

itly

boun

dm

ultip

letim

es, r

athe

r tha

nus

ing

the*

oper

ator

. For

exam

ple,

args:Exp*

coul

dbe

repl

aced

byArgs?

whe

reArgs

::=args:Exp

(","Args)?

.Fo

r for

mat

ting,

the

regu

lar o

pera

tors

*an

d+

prov

ide

addi

tiona

l sem

antic

s,al

low

ing

the

form

atte

r to

perf

orm

inte

llige

ntgr

oupi

ngan

din

dent

atio

n.A

repe

ated

grou

pis

eith

erfo

rmat

ted

onon

elin

e,or

else

itis

inde

nted

and

brok

enin

tom

ultip

lelin

esif

itis

too

long

.

2.4

Ref

eren

ceR

esol

utio

n

Inor

der t

oex

plai

npa

th-b

ased

refe

renc

ere

solu

tion

inO

bjec

t Gra

mm

ars,

itis

inst

ruct

ive

toin

trodu

cea

slig

htly

mor

eel

abor

ate

exam

ple.

Con

side

r asm

all D

SLfo

r mod

elin

gst

ate

mac

hine

s.Fi

gure

1di

spla

ysth

ree

repr

esen

tatio

nsof

asi

mpl

est

ate

mac

hine

repr

esen

ting

ado

orth

atca

nbe

open

ed, c

lose

d,an

dlo

cked

. Fig

ure

1(a)

show

sth

est

ate

mac

hine

ingr

aphi

cal n

otat

ion.

The

sam

est

ate

mac

hine

isre

nder

edte

xtua

llyin

Fig.

1(b)

. Int

erna

lly,

the

mac

hine

itsel

f,its

stat

esan

dth

etra

nsiti

ons

are

all r

epre

sent

edex

plic

itly

asob

ject

s.Th

isis

illus

trate

din

the

obje

ctdi

agra

mgi

ven

inFi

g.1(

c).

The

obje

ctdi

agra

mco

nfor

ms

toth

eSt

ate

Mac

hine

sche

ma

give

nin

Fig.

2.Th

esc

hem

aco

nsis

tsof

alis

t of n

amed

clas

ses,

each

havi

nga

list o

f fiel

dsde

fined

bya

nam

e,a

type

, and

som

eop

tiona

l mod

ifier

s.Fo

r exa

mpl

e,th

eMachine

clas

sha

sa

field

nam

edstates

whi

chis

ase

t of S

tate

obje

cts.

The*

afte

r the

type

nam

eis

am

odifi

erth

atm

arks

the

field

asm

any-

valu

ed. T

he#

anno

tatio

nm

arks

afie

ldas

apr

imar

yke

y,as

isth

eca

sefo

r the

name

field

ofth

eSt

ate

clas

s.A

sa

resu

lt,st

ate

nam

esm

ust b

eun

ique

and

thestates

field

ofMachine

can

bein

dexe

dby

nam

e.Th

e/

anno

tatio

naf

ter t

hemachine

field

indi

cate

s tha

t the

machine

andstates

are

inve

rses

, as a

refrom

/out

andto

/in.

The!

Monday, October 1, 12

Page 34: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened

Closed

Locked

close

open

unlock

lock

(a)

startOpened

stateOpened

onclosego

Closed

stateClosed

onopen

goOpened

onlock

goLocked

stateLocked

onunlock

goClosed

(b)

:Mac

hine

nam

e: "O

pene

d"

:Sta

te

nam

e: "C

lose

d"

:Sta

te

nam

e: "L

ocke

d"

:Sta

te

even

t: "c

lose

"

: Tra

nsiti

on

even

t: "o

pen"

:Tra

nsiti

on

even

t: "lo

ck"

: Tra

nsiti

on

even

t: "u

nloc

k"

:Tra

nsiti

on

from

out

in

to in

to

in

from

out

from

stat

esst

ates

out

from

to

stat

es

mac

hine

out

in

to

star

t

(c)

Fig.

1.(a

) Exa

mpl

est

ate

mac

hine

ingr

aphi

cal n

otat

ion,

(b) t

hest

ate

mac

hine

inte

xtua

l not

atio

n,an

d(c

) the

inte

rnal

repr

esen

tatio

nof

the

stat

em

achi

nein

obje

ctdi

agra

mno

tatio

n

The

regu

lar r

epet

ition

gram

mar

oper

ator

*m

aybe

optio

nally

follo

wed

bya

sepa

rato

rus

ing@,

whi

chin

this

case

isa

com

ma.

Theargs

field

ofth

eCall

clas

s is a

ssig

ned

obje

cts

crea

ted

byze

ro-o

r-m

ore

occu

rren

ces

ofExp.

Aco

llect

ion

field

can

also

beex

plic

itly

boun

dm

ultip

letim

es, r

athe

r tha

nus

ing

the*

oper

ator

. For

exam

ple,

args:Exp*

coul

dbe

repl

aced

byArgs?

whe

reArgs

::=args:Exp

(","Args)?

.Fo

r for

mat

ting,

the

regu

lar o

pera

tors

*an

d+

prov

ide

addi

tiona

l sem

antic

s,al

low

ing

the

form

atte

r to

perf

orm

inte

llige

ntgr

oupi

ngan

din

dent

atio

n.A

repe

ated

grou

pis

eith

erfo

rmat

ted

onon

elin

e,or

else

itis

inde

nted

and

brok

enin

tom

ultip

lelin

esif

itis

too

long

.

2.4

Ref

eren

ceR

esol

utio

n

Inor

der t

oex

plai

npa

th-b

ased

refe

renc

ere

solu

tion

inO

bjec

t Gra

mm

ars,

itis

inst

ruct

ive

toin

trodu

cea

slig

htly

mor

eel

abor

ate

exam

ple.

Con

side

r asm

all D

SLfo

r mod

elin

gst

ate

mac

hine

s.Fi

gure

1di

spla

ysth

ree

repr

esen

tatio

nsof

asi

mpl

est

ate

mac

hine

repr

esen

ting

ado

orth

atca

nbe

open

ed, c

lose

d,an

dlo

cked

. Fig

ure

1(a)

show

sth

est

ate

mac

hine

ingr

aphi

cal n

otat

ion.

The

sam

est

ate

mac

hine

isre

nder

edte

xtua

llyin

Fig.

1(b)

. Int

erna

lly,

the

mac

hine

itsel

f,its

stat

esan

dth

etra

nsiti

ons

are

all r

epre

sent

edex

plic

itly

asob

ject

s.Th

isis

illus

trate

din

the

obje

ctdi

agra

mgi

ven

inFi

g.1(

c).

The

obje

ctdi

agra

mco

nfor

ms

toth

eSt

ate

Mac

hine

sche

ma

give

nin

Fig.

2.Th

esc

hem

aco

nsis

tsof

alis

t of n

amed

clas

ses,

each

havi

nga

list o

f fiel

dsde

fined

bya

nam

e,a

type

, and

som

eop

tiona

l mod

ifier

s.Fo

r exa

mpl

e,th

eMachine

clas

sha

sa

field

nam

edstates

whi

chis

ase

t of S

tate

obje

cts.

The*

afte

r the

type

nam

eis

am

odifi

erth

atm

arks

the

field

asm

any-

valu

ed. T

he#

anno

tatio

nm

arks

afie

ldas

apr

imar

yke

y,as

isth

eca

sefo

r the

name

field

ofth

eSt

ate

clas

s.A

sa

resu

lt,st

ate

nam

esm

ust b

eun

ique

and

thestates

field

ofMachine

can

bein

dexe

dby

nam

e.Th

e/

anno

tatio

naf

ter t

hemachine

field

indi

cate

s tha

t the

machine

andstates

are

inve

rses

, as a

refrom

/out

andto

/in.

The!

Monday, October 1, 12

Page 35: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Object path to find the start state with

name it

start M

M ::= [Machine] "start" \start:</states[it]> states:S*

S ::= [State] "state" name:sym out:T*

T ::= [Transition] "on" event:sym "go" to:</states[it]>

Fig. 3. Object Grammar to parse state machines

When humans read the textual presentation in Fig. 1(b), they immediately resolve thenames in each transition to create a mental picture similar Fig. 1(a).

Figure 3 shows an Object Grammar for state machines5. It uses the reference</states[it]> to look up the start state of a machine and to find the the target state ofa transition. The path /states[it] starts at the root of the resulting object model, asindicated by the forward slash /. In this case the root is a Machine object, since M isthe start symbol of the grammar, and the M production creates a Machine. The path thennavigates into the field states of the machine (see Fig. 2), and uses the identifier fromthe input stream to index into the keyed collection of all states. The same path is used toresolve the to field of a transition to the target state.

Path ::= [Anchor] type:"."

| [Anchor] type:".."

|

[Sub] parent:Path? "/" name:sym Subscript?

Subscript

::= "[" key:Key "]"

Key ::= Path | [It] "it"

Fig. 4. Syntax of paths.

References and Paths In gen-eral, a reference <p> representsa lookup of an object using thepath p. Parsing a reference al-ways consumes a single identi-fier, which can be used as a keyfor indexing into keyed collec-tions. Binding a field to a refer-ence thus results in a cross-linkfrom the current object to the ref-erenced object.

The syntax of paths is given in Fig. 4. A path is anchored at the current object (.), atits parent (..), or at the root. In the context of an object a path can descend into a field bypost-fixing a path with / and the name of the field. If the field is a collection, a specificelement can be referenced by indexing in square brackets. The keyword it representsthe string-typed value of the identifier in the input stream that represents the referencename.

The grammar of schemas, given in Fig. 5, illustrates a more complex use of references.To lookup inverse fields, it is necessary to look for the field within the class that is thetype of the field. For example, in the state machine schema in Fig. 1(b), the field from inTransition has type State and its inverse is the out field of State. The path for the typeis type:</types[it]>, while the path for the inverse is inverse:<./type/fields[it]>,

5 The field label start is escaped using \ because start is a keyword in the grammar of grammars;cf. Section 2.7.

Monday, October 1, 12

Page 36: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Paths

• Navigate the resulting model along

• Fields

• Collections (keyed, positional)

• NB: model may not be finished yet

• Paths may traverse cross links too

• Iterative fix point

Monday, October 1, 12

Page 37: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

A path

start M

M ::= [Machine] "start" \start:</states[it]> states:S*S ::= [State] "state" name:sym out:T*T ::= [Transition] "on" event:sym "go" to:</states[it]>

Fig. 3. Object Grammar to parse state machines

When humans read the textual presentation in Fig. 1(b), they immediately resolve thenames in each transition to create a mental picture similar Fig. 1(a).

Figure 3 shows an Object Grammar for state machines5. It uses the reference</states[it]> to look up the start state of a machine and to find the the target state ofa transition. The path /states[it] starts at the root of the resulting object model, asindicated by the forward slash /. In this case the root is a Machine object, since M isthe start symbol of the grammar, and the M production creates a Machine. The path thennavigates into the field states of the machine (see Fig. 2), and uses the identifier fromthe input stream to index into the keyed collection of all states. The same path is used toresolve the to field of a transition to the target state.

Path ::= [Anchor] type:"."

| [Anchor] type:".."

|

[Sub] parent:Path? "/" name:sym Subscript?

Subscript

::= "[" key:Key "]"

Key ::= Path | [It] "it"

Fig. 4. Syntax of paths.

References and Paths In gen-eral, a reference <p> representsa lookup of an object using thepath p. Parsing a reference al-ways consumes a single identi-fier, which can be used as a keyfor indexing into keyed collec-tions. Binding a field to a refer-ence thus results in a cross-linkfrom the current object to the ref-erenced object.

The syntax of paths is given in Fig. 4. A path is anchored at the current object (.), atits parent (..), or at the root. In the context of an object a path can descend into a field bypost-fixing a path with / and the name of the field. If the field is a collection, a specificelement can be referenced by indexing in square brackets. The keyword it representsthe string-typed value of the identifier in the input stream that represents the referencename.

The grammar of schemas, given in Fig. 5, illustrates a more complex use of references.To lookup inverse fields, it is necessary to look for the field within the class that is thetype of the field. For example, in the state machine schema in Fig. 1(b), the field from inTransition has type State and its inverse is the out field of State. The path for the typeis type:</types[it]>, while the path for the inverse is inverse:<./type/fields[it]>,which refers to the type object. To resolve these paths, the parser must iteratively evaluatepaths until all paths have been resolved.

5 The field label start is escaped using \ because start is a keyword in the grammar of grammars;cf. Section 2.7.

start at the root

navigate into states

use the parsed identifier as key

Paths can also start at current object (.) or parent (..)

Monday, October 1, 12

Page 38: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 39: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Monday, October 1, 12

Page 40: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

Monday, October 1, 12

Page 41: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

Monday, October 1, 12

Page 42: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

Monday, October 1, 12

Page 43: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

Monday, October 1, 12

Page 44: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

Monday, October 1, 12

Page 45: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 46: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 47: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 48: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 49: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 50: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

Monday, October 1, 12

Page 51: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

Monday, October 1, 12

Page 52: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

Monday, October 1, 12

Page 53: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

Monday, October 1, 12

Page 54: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

Monday, October 1, 12

Page 55: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

Monday, October 1, 12

Page 56: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

Monday, October 1, 12

Page 57: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

Monday, October 1, 12

Page 58: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

Monday, October 1, 12

Page 59: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

Monday, October 1, 12

Page 60: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 61: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 62: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 63: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Creating cross linksOpened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

Opened Closed Lockedclose

open unlock

lock

(a)

start Opened

state Opened

on close go Closed

state Closed

on open go Opened

on lock go Locked

state Locked

on unlock go Closed

(b)

:Machine

name: "Opened"

:State

name: "Closed"

:State

name: "Locked"

:State

event: "close"

: Transition

event: "open"

:Transition

event: "lock"

: Transition

event: "unlock"

:Transition

from

out

in

to

in

to

infrom

out

from

states states

out

fromto

states

machine

outin

to

start

(c)

Fig. 1. (a) Example state machine in graphical notation, (b) the state machine in textual notation,and (c) the internal representation of the state machine in object diagram notation

The regular repetition grammar operator * may be optionally followed by a separatorusing @, which in this case is a comma. The args field of the Call class is assigned objectscreated by zero-or-more occurrences of Exp. A collection field can also be explicitlybound multiple times, rather than using the * operator. For example, args:Exp* could bereplaced by Args? where Args ::= args:Exp (","Args)?.

For formatting, the regular operators * and + provide additional semantics, allowingthe formatter to perform intelligent grouping and indentation. A repeated group is eitherformatted on one line, or else it is indented and broken into multiple lines if it is toolong.

2.4 Reference Resolution

In order to explain path-based reference resolution in Object Grammars, it is instructiveto introduce a slightly more elaborate example. Consider a small DSL for modeling statemachines. Figure 1 displays three representations of a simple state machine representinga door that can be opened, closed, and locked. Figure 1(a) shows the state machine ingraphical notation. The same state machine is rendered textually in Fig. 1(b). Internally,the machine itself, its states and the transitions are all represented explicitly as objects.This is illustrated in the object diagram given in Fig. 1(c).

The object diagram conforms to the State Machine schema given in Fig. 2. Theschema consists of a list of named classes, each having a list of fields defined by a name,a type, and some optional modifiers. For example, the Machine class has a field namedstates which is a set of State objects. The * after the type name is a modifier that marksthe field as many-valued. The # annotation marks a field as a primary key, as is thecase for the name field of the State class. As a result, state names must be unique andthe states field of Machine can be indexed by name. The / annotation after the machine

field indicates that the machine and states are inverses, as are from/out and to/in. The !

start:</states[“Opened”]>

to:</states[“Closed”]>

to:</states[“Opened”]>

to:</states[“Locked”]>

to:</states[“Closed”]>

Monday, October 1, 12

Page 64: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Assessment

• Bi-directional & compositional

• Flexible:

• interleaved data binding

• path-based references & predicates

• formatting hints

• Self-described

Monday, October 1, 12

Page 65: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Composition in Ensō

Grammar Schema StencilAuth

CommandExpr

Web

XMLPath

Controller

Fig. 11. Language composition in Enso. Each arrow A ! B indicates an invocation of B�A.

arrow points in the direction of the result. For instance, the Stencil and Web languagesare, independently, merged into the Command language. As a result both Stencil andWeb include, and possibly override and/or extend the Command language. If a languagereuses or extends multiple other languages, the merge operator is applied in sequence.For instance, Grammar is first merged into Path, and then merged into Expr.

The core languages in Enso include both the Schema and Grammar languages, aswell as Stencil, a language to define graphical model editors. Additionally, Enso featuresa small set of library languages that are not deployed independently but reused in otherlanguages. An example of a library language is Expr, an expression language withoperators, variables and primitive values. It is, for instance, reused in Grammar forpredicates and in Schema for computed fields. Command is a control-flow language thatcaptures loops, conditional statements and functions. The Command language reuses theExpr language for the guards in loops and conditional statements. Another example isthe language of paths (Path), shown in Fig. 4, which provides a model to address nodesin object graphs.

The reuse of Expr and Path are examples of a simple embedding. The languages arereused as black boxes, without modification. The composition of Command with Stenciland Web, however is different. Stencil is created by adding language constructs foruser-interface widgets, lines, and shapes to the Command language as valid primitives.The Command language can now be used to create diagrams. A similar extension isrealized in the Web language: here a language for XML element structure is mixed withthe statement language of Web. The extension works in both directions: XML elementsare valid statements, statements are valid XML content. The Piping and Controllerlanguages are from a domain-specific modeling case-study in the domain of piping andinstrumentation for the Language Workbench Challenge 2012 [25]. Fig. 11 only showsthe Controller part which reuses Expr.

An overview of the number source lines of code (SLOC) is shown in Table 1(a).We show the number for the full languages in Enso as well as the reused languagemodules (Path, Command, Expr and XML). A language consists of a schema, a grammarand an interpreter. The interpreters are all implemented in Ruby. Table 1(b) showsthe reuse percentage for each language [17]. This percentage is computed as 100⇥#SLOCreused/#SLOCtotal. Which languages are reused in each case can be seen fromFig. 11. As can be seen from this table, the amount of reuse in schemas and grammars isconsistently high, with the exception of the Piping language, which does not reuse any

Monday, October 1, 12

Page 66: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

Conclusion

• Object grammars: mapping text to objects and vice versa

• Declarative paths for resolving cross-references

• Flexible, bi-directional and compositional

• Foundation of Ensō

Monday, October 1, 12

Page 67: Object Grammarsstorm/publications/enso... · 2012. 10. 1. · the formatter to perform intelligent grouping and indentation. A repeated group is either formatted on one line, or else

http://www.enso-lang.org/

Monday, October 1, 12