• Aucun résultat trouvé

Convenient Extensions

Symbol Edge Kind

6.2 CLASS DICTIONARY GRAPH RULES

6.2.1 Convenient Extensions

Class dictionary graphs with construction and alternation edges provide the important mod-eling power for describing object structures. Repetition classes can be simulated with con-struction and repetition classes as Fig. 6.13 shows. But for practical applications it is convenient to have repetition classes directly available. The same applies to optional parts.

The optional part in

Meal =

<appetizer> Appetizer

<entree> Entree [<dessert> Dessert].

6.2. CLASSDICTIONARY GRAPHRULES 147 can be simulated by

Meal =

<appetizer> Appetizer

<entree> Entree

<dessert> OptDessert.

OptDessert : Dessert | Empty.

Empty = .

A class dictionary graph G = (V C;V A;V R;;EC;ECO;EA;ER;ERO) consists of construction verticesV C, alternation verticesV A, repetition verticesV R,V =V C[V A[ V R, labels , construction edgesEC, optional construction edgesECO, alternation edges EA, repetition edgesER, and optional repetition edgesERO. Construction edges, including the optional ones, are represented as triples: (Vertex inV C[V A, Label in , Vertex inV).

Alternation edges are represented as pairs: (Alternation vertex inV A, Vertex inV C[V A).

Repetition edges, including the optional ones, are represented as pairs: (Vertex in V R, Vertex inV).

Notice that by this denition, construction edges can exit only from construction or alternation vertices. Furthermore, an alternation edge cannot terminate in a repetition vertex. The reason is that a repetition class cannot inherit parts from super classes.

Edges in a class dictionary graph cannot start from any vertex kind and go to any other vertex kind. The edge/vertex restrictions are summarized below. V T is explained in the next paragraph.

VC VA VR VT

----|---EC | from/to from/to /to /to

ECO | from/to from/to /to /to

EA | /to from/to

ER | /to /to from/to /to

ERO | /to /to from/to /to

For practical purposes it is convenient to use predened classes for the most common objects, such as numbers, identiers, strings, etc. For this purpose we use a fourth class kind, called terminal classes. The terminal classes that we use are: DemNumber, DemReal, DemIdent, DemString, DemText. V T is the set of terminal classes and the table below summarizes the edge/vertex restrictions with the presence of V T. No edge can originate from a terminal class since they are terminal. An alternation edge cannot terminate in a terminal class since it would alter a predened class.

A graphical version of the previous table is in Fig. 6.14. Terminal classes have a T inside the symbol. The illegal connections are crossed out.

In addition to the previous table there are the following restrictions. A construction or alternation vertex can have zero or more outgoing edges of the EC and ECO kind.

A repetition vertex has exactly one outgoing edge, either of the ER or ERO kind. An alternation vertex has at least one outgoing edge of theEAkind.

148 CHAPTER 6. CLASSDICTIONARY GRAPHSANDOBJECTS

l l

l l

EC

ECO

EA

ER

ERO

VC From/To

l l

l l

From/To VA

l l

l l

From/To VR

EC

ECO

EA

ER

ERO

T l T

T l T

l

l

T T

T T

T T

From/To VT

l l

EC ER ECO EA ERO

Edge/Vertex Restrictions for Class Dictionary Graphs

Figure 6.14: Connections

6.3. OBJECTS 149

class kind A(S)

construction classS = ... unit setfSg repetition classS ~ ... unit setfSg

alternation class union ofA(X)A(Y)A(Z) ...

S : X|Y|Z...

Figure 6.15: Denition of associated

6.3 OBJECTS

The purpose of a class dictionary graph is to dene classes, which in turn dene sets of objects.3

There is a xed number of terminal classes that dene

terminal objects

. The terminal objects represent a value such as a number, an identier, or a string. These objects are instances of the classes DemNumber, DemReal, DemIdent, DemString, DemText, respectively.

In addition to the terminal objects, there are

composite

objects that are dened by the class denitions. A special case of the composite objects are the ones without a part.

They are called

atomic

objects. The classA = .denes only atomic objects.

To dene the set of legal4 objects with respect to a class dictionary graph, we need to dene, for any class S, the setA(S) of construction classes associated with S. The set of classes

associated

with a class is given in Fig. 6.15. It is the set of construction classes that are reachable through alternation edges from classS.

IfT is a set of construction classes then aT-object is an object that is an instance of a class in T. A

legal object

with respect to a class dictionary graph is dened inductively as follows. Nothing is a legal object except by virtue of one of the following rules.

1. Every atomic object and every terminal object is a legal object.

2. The following composite objects are legal objects:

(a) If there is a nonempty class denition

A = <p1> C1 <p2> C2 ...

then an A-object is legal if all the p1-parts are A(C1)-objects and if all the p2-parts areA(C2)-objects, etc. An optional part of a construction class may be nil

= NULL.

If A is used as an alternative of an alternation class denition, then the A-objects get all the parts that are dened after *common*: If Ai appears in

Q : A1 | A2 | ... *common* <m1> M1 <m2> M2 ...

then Ai-objects have an m1-part that is anA(M1)-object and an m2-part that is anA(M2)-object, etc.

3Object graph recognition, page 436 (24).

4Legal object graph, page 436 (27).

150 CHAPTER6. CLASSDICTIONARY GRAPHSANDOBJECTS

(b) If there is a class denition

A ~ {B}.

then a legal A-object is an object that has an ordered sequence of legal A (B)-objects as parts.

(c) If there is a class denition

A ~ B {B}.

then a legal A-object is an object that has a nonempty ordered sequence of legal

A(B)-objects as parts.

This denition of legal objects allows objects that share subparts and even circular objects. Instances of the same class may be substituted for each other without changing the legality of an object.

2a can be simplied, if we use the attening operation.5 A class dictionary graphG1 is the

attened

form of a class dictionary graphG2, if inG1 all parts have been pushed down the alternation edges to construction classes. After the attening, no alternation class has common parts. Flat class dictionary graphs are usually not written by the user but are produced from nonat class dictionary graphs by tools. Flat class dictionary graphs are a useful intermediate form. Notice that the attening operation is well dened since there can be no cycles of alternation edges in a class dictionary graph.

Next we introduce a textual notation for objects.