Concrete Syntax of Context Declarations

This section describes the concrete syntax for specifying the context of the different types of usage of OCL expressions.

It makes use of grammar rules defined in Chapter 9 ("Concrete Syntax"). Here too, every production rule is associated to the abstract syntax by the type of the attribute ast. However, we must sometimes refer to the abstract syntax of the UML to find the right type for each production.

Visibility rules etc. must be defined in the UML metamodel. Here we assume that every classifier has an operation visibleElements(), which returns an instance of type Environment, as defined in chapter 9 ("Concrete Syntax").

Note ­ The context declarations as described in this section are not needed when the OCL expressions are attached directly to the UML model. This concerete syntax for context declarations is only there to facilitate separate OCl expressions in text iles.

Because of the assumption that the concrete syntax below is used separate from the UML model, we assume the existence of an operation getClassifier() on the UML model that allows us to find a Classifier anywhere in the corresponding model. The signature of this operation is defined as follows:

context Model::findClassifier( pathName : Sequence(String) ) : Classifier

The pathName needs not be a fully qualified name (it may be), as long as it can uniquely identify the classifier siomewhere in the UML model. If a classifier name occurs more than once, it needs to be qualified with its owning package (recusiveley) until the qualified name is unique. If more than one classifier is found, the operation returns OclUndefined. The variable Model is used to refer to the UML Model. It is used as Model.findClassifier().

Likewise, we assume the existence of an operation getPackage() on the UML model that allows us to find a Package anywhere in the corresponding model. The signature of this operation is defined as follows:

context Model::findPackage( pathName : Sequence(String) ) : Package

In this case the pathName needs be a fully qualified name.

Note ­ The rules for the synthesized and inherited attributes associated with the grammar all depend upon the UML 2.0 metamodel. They cannot be written until this metamodel has been stablelized. Therefore only the grammar rules are given.
 

packageDeclarationCS

This production rule represents a package declaration.

[A] packageDeclarationCS ::= 'package' pathNameCS contextDeclCS*
'endpackage'

[B] packageDeclarationCS ::= contextDeclCS*
 

contextDeclarationCS

This production rule represents all different context declarations.

[A] contextDeclarationCS ::= attrOrAssocContextCS
[C] contextDeclarationCS ::= classifierContextDeclCS
[D] contextDeclarationCS ::= operationContextDeclCS
 

attrOrAssocContextCS

This production rule represents a context declaration for expressions that can be coupled to an attribute or association end.

The path name refers to the "owner" of the attribute or association end, the simple name refers to its name, the type states its type.

attrOrAssocContextCS ::= 'context' pathNameCS '::' simpleName':' typeCS
initOrDerValueCS
 

initOrDerValueCS

This production rule represents an initial or derived value expression.

[A] initOrDerValueCS[1] ::= 'init' ':' OclExpression
     initOrDerValueCS[2]?

[B] initOrDerValueCS[1] ::= 'derive' ':' OclExpression
    initOrDerValueCS[2]?
 

classifierContextDeclCS

This production rule represents a context declaration for expressions that can be coupled to classifiers.

classifierContextDeclCS ::= 'context' pathNameCS invOrDefCS
 

invOrDefCS

This production rule represents an invariant or definition.

[A] invOrDefCS[1] ::= 'inv' (simpleNameCS)? ':' OclExpressionCS
    invOrDefCS[2]

[B] invOrDefCS[1] ::= 'def' (simpleNameCS)? ':' defExpressionCS
    invOrDefCS[2]
 

defExpressionCS

This production rule represents a definition expression. The defExpressionCS nonterminal has the purpose of defining additional attributes or operations in OCL. They map directly to a UML attribute or operation with a constraint that defines the derivation of the attribute or operation result value. Note that VariableDeclarationCS has been defined in Chapter 9.

[A] defExpressionCS ::= VariableDeclarationCS '=' OclExpression
[B] defExpressionCS ::= operationCS '=' OclExpression
 

operationContextDeclCS

This production rule represents a context declaration for expressions that can be coupled to an operation.

operationContextDeclCS ::= 'context' operationCS prePostOrBodyDeclCS
 

prePostOrBodyDeclCS

This production rule represents a pre- or postcondition or body expression.

[A] prePostOrBodyDeclCS[1] ::= 'pre' (simpleNameCS)? ':' OclExpressionCS
      prePostOrBodyDeclCS[2]?

[B] prePostOrBodyDeclCS[1] ::= 'post' (simpleNameCS)? ':' OclExpressionCS
     prePostOrBodyDeclCS[2]?

[C] prePostOrBodyDeclCS[1] ::= 'body' (simpleNameCS)? ':' OclExpressionCS
     prePostOrBodyDeclCS[2]?
 

operationCS

This production rule represents an operation in a context declaration or definition expression.

[A] operationCS ::= pathNameCS '::' simpleNameCS '(' parametersCS? ')' ':'
     typeCS?

[B] operationCS ::= simpleNameCS '(' parametersCS? ')' ':' typeCS?
 

parametersCS

This production rule represents the formal parameters of an operation .

parametersCS[1] ::= VariableDeclarationCS (',' parametersCS[2] )?