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.
[A] packageDeclarationCS
::= 'package' pathNameCS contextDeclCS*
'endpackage'
[B] packageDeclarationCS
::= contextDeclCS*
[A] contextDeclarationCS
::= attrOrAssocContextCS
[C] contextDeclarationCS
::= classifierContextDeclCS
[D] contextDeclarationCS
::= operationContextDeclCS
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
[A] initOrDerValueCS[1]
::= 'init' ':' OclExpression
initOrDerValueCS[2]?
[B] initOrDerValueCS[1]
::= 'derive' ':' OclExpression
initOrDerValueCS[2]?
classifierContextDeclCS
::= 'context' pathNameCS invOrDefCS
[A] invOrDefCS[1] ::=
'inv' (simpleNameCS)? ':' OclExpressionCS
invOrDefCS[2]
[B] invOrDefCS[1] ::=
'def' (simpleNameCS)? ':' defExpressionCS
invOrDefCS[2]
[A] defExpressionCS ::=
VariableDeclarationCS '=' OclExpression
[B] defExpressionCS
::= operationCS '=' OclExpression
operationContextDeclCS
::= 'context' operationCS prePostOrBodyDeclCS
[A] prePostOrBodyDeclCS[1]
::= 'pre' (simpleNameCS)? ':' OclExpressionCS
prePostOrBodyDeclCS[2]?
[B] prePostOrBodyDeclCS[1]
::= 'post' (simpleNameCS)? ':' OclExpressionCS
prePostOrBodyDeclCS[2]?
[C] prePostOrBodyDeclCS[1]
::= 'body' (simpleNameCS)? ':' OclExpressionCS
prePostOrBodyDeclCS[2]?
[A] operationCS ::= pathNameCS
'::' simpleNameCS '(' parametersCS? ')' ':'
typeCS?
[B] operationCS ::= simpleNameCS
'(' parametersCS? ')' ':' typeCS?
parametersCS[1] ::= VariableDeclarationCS
(',' parametersCS[2] )?