Professional Documents
Culture Documents
ATL Reference Manual
ATL Reference Manual
2005
by
ATLAS group
LINA & INRIA
Nantes
Content
1
Introduction ....................................................................................................................... 1
QVT................................................................................................................................ 1
ATL and QVT ................................................................................................................ 1
OCL................................................................................................................................ 1
Objectives and Rationale................................................................................................ 1
2
Grammar............................................................................................................................ 1
2.1 Context-Free Grammar .................................................................................................. 1
2.2 Grammar Notation.......................................................................................................... 2
3
Lexical Structure ............................................................................................................... 2
3.1 Encoding......................................................................................................................... 2
3.2 Lexical Translations ....................................................................................................... 3
3.3 Unicode Escapes ............................................................................................................ 3
3.4 Line Terminators ............................................................................................................ 3
3.5 Input Elements and Tokens ............................................................................................ 4
3.6 White Space.................................................................................................................... 4
3.7 Comments....................................................................................................................... 4
3.8 Identifiers ....................................................................................................................... 4
3.9 Keywords ....................................................................................................................... 5
3.10 Separators ....................................................................................................................... 6
3.11 Operators ........................................................................................................................ 6
3.12 Infix Operators ............................................................................................................... 6
4
Data Model........................................................................................................................ 7
4.1 OclAny ........................................................................................................................... 7
4.2 Model Elements.............................................................................................................. 7
4.3 Primitive Types .............................................................................................................. 8
4.3.1
The Boolean Type .................................................................................................. 8
4.3.2
The String Type...................................................................................................... 9
4.3.3
Numeric Types ....................................................................................................... 9
4.4 Collections.................................................................................................................... 11
4.4.1
Set......................................................................................................................... 12
4.4.2
OrderedSet............................................................................................................ 13
4.4.3
Bag ....................................................................................................................... 14
4.4.4
Sequence............................................................................................................... 15
4.4.5
Iterator Expressions.............................................................................................. 16
4.5 Tuples ........................................................................................................................... 18
4.6 Enumerations................................................................................................................ 18
5
ATL Programs................................................................................................................. 18
5.1 Modules........................................................................................................................ 18
5.1.1
Header Section ..................................................................................................... 19
5.1.2
Import Section ...................................................................................................... 19
5.2 Queries ......................................................................................................................... 19
5.3 Libraries ....................................................................................................................... 19
6
OCL Expressions............................................................................................................. 20
6.1 The If Expression ......................................................................................................... 20
1.1
1.2
1.3
1.4
1 Introduction
ATL, the Atlas Transformation Language, is the ATLAS INRIA & LINA research group
answer to the OMG MOF [5][6] /QVT RFP [6]. It is a model transformation language
specified both as a metamodel and as a textual concrete syntax. It is a hybrid of declarative
and imperative. The preferred style of transformation writing is declarative, which means
simple mappings can be expressed simply. However, imperative constructs are provided so
that some mappings too complex to be declaratively handled can still be specified. An ATL
transformation program is composed of rules that define how source model elements are
matched and navigated to create and initialize the elements of the target models.
1.1 QVT
QVT is an acronym for Query, View and Transformation. This is how they are described in
QVT RFP [6]:
Queries take as input a model, and select specific elements from that model.
Views are models that are derived from other models.
Transformations take as input a model and update it or create a new model.
1.3 OCL
ATL is based on OCL [7], the Object Constraint Language. ATL supports OCL expressions
(see chapter 6) and it has a type model (see chapter 4) that is very similar to the one of OCL.
2 Grammar
To describe ATL, an EBNF-like context-free grammar has been chosen.
Page 1
Left-side terminals or nonterminals can be declared optional with the opt keyword.
Input :
InputElementsopt
The above means that an input may consist of input elements but an input may also be empty.
If a line is too short, the content can be split on several lines. While alternatives start at the
same indention, split lines have additional indention.
TargetPatternElement :
Identifier : MetamodelClassPath ( Assignements )
Identifier : distinctopt MetamodelClassPath
foreach (Identifier in Identifier ) ( Assignements )
The definition contains two alternatives starting with the nonterminal identifier. The second left side alternative
is split on two lines.
3 Lexical Structure
3.1 Encoding
ATL programs are written using the Unicode character set. Except for comments, identifiers,
and the contents of character and string literals, all input elements in an ATL program are
formed only from ASCII characters (or Unicode escapes which result in ASCII characters).
Information about the Unicode encoding standard can be found in the Unicode Standard [9].
ASCII characters are the first 128 characters of the Unicode character encoding.
Page 2
Page 3
3.7 Comments
Comments start with two consecutive hyphens and end with the line terminator.
Comment :
-- CharactersInLineopt LineTerminator
CharactersInLine :
InputCharacter
CharactersInLine InputCharacter
3.8 Identifiers
Please note that OCL identifiers are defined as String and String as a chain of characters
which is not restricted to specific characters. myVariable is a possible name for an identifier
as much as 4any-thing2:) (a mix of signs, digits and letters).
Identifiers are unlimited sequences of specific Unicode characters and are defined as follows:
Identifier :
IdentifierChars but not Keyword, BooleanLiteral or NullLiteral
UnicodeInputCharacters
Page 4
UnicodeInputCharacters :
UnicodeInputCharacter
UnicodeInputCharacter UnicodeInputCharacters
IdentifierChars :
LetterOrDigit
IdentifierChars LetterOrDigit
Letter :
any Unicode character between a and z or A and Z
LetterOrDigit :
any Letter or any Unicode character between 0 and 9
Identifier declarations with chains of Unicode input characters containing none identifier
characters have to be put in double inverted commas (similar rules apply to keywords).
However, what has not yet been specified (and this applies only to chains of Unicode input
characters containing none identifier characters and not to keywords) is that when identifiers
are used (and not declared) in the program double inverted commas are not necessary. Thus
the following code is also possible:
query TestOperatorDefinition = '123' - 2;
helper context String def: "-"(i : Integer) : String =
self.substring(1,self.size() - i);
3.9 Keywords
The following words are ATL keywords:
Keyword : one of
not
module
def
to
do
let
and
create
context
mapsTo
if
library
or
from
rule
distinct
then
query
Page 5
xor
uses
using
foreach
else
for
implies
helper
derived
in
endif
3.10 Separators
The following nine ASCII characters are the separators (punctuators):
Separator : one of
(
)
.
3.11 Operators
Operators can be used by the ASCII
Operator:
UnaryOperator
BinaryOperator
The following tokens are basic operators. They are formed from ASCII characters:
UnaryOperator : one of
+
BinaryOperator
=
+
div
: one of
>
<
*
mod
not
<=
/
>=
&
!=
|
OperatorExpression :
UnaryOperator Expression
Expression . UnaryOperator ()
Expression BinaryOperator Expression
Expression . BinaryOperator ( Expression )
The operators are listed in precedence order with the highest precedence at the top of the
table:
Priority of operators
precedence
@pre
brackets, dot and arrows
[] () {} . <unary
+ - not
multiplicative
*/%
additive
+if-clause
if-then-else-endif
relational
< <= > >=
equality
= <>
logical AND
and
logical OR and XOR
or xor
logical implies
implies
Page 6
4 Data Model
ATL is a strongly typed language since every expression has a type that is known at compile
time.
The ATL type model is very similar to the OCL type model; in particular what concerns the
primitive types, the model elements and the collection types
4.1 OclAny
An important superclass of the OCL type system is OclAny from which, among others,
OclModelElement, OclType, Real, Boolean and String inherit.
OclAny = OclAny : Boolean
Returns true if the objects are the same, otherwise false.
OclAny <> OclAny : Boolean
Returns false if the objects are the same, otherwise true.
OclAny oclIsNew : Boolean
Returns true if the object is newly created (i.e. didnt exist at precondition time), otherwise
false.
OclAny oclIsTypeOf( OclType ) : Boolean
Returns true if the object is of the OclType specified, otherwise false.
OclAny oclIsKindOf( OclType ) : Boolean
Returns true if the objects conforms to the OclType specified (thus also to any of its
subclasses), otherwise false.
OclType allInstances : Set
Returns all instances of a type (that are in a given source model).
OclAny oclIsUndefined : Boolean
Returns true if the object is void (void is represnted by OclVoid), otherwise false.
In OCL there is no numeric type. The ATL numeric type and the ATL Real correspond to
OCL Real. Numeric type has only been used to facilitate the specification of ATL.
implies
-------
substring()
Page 9
toInteger()
The ATL language does not specify numeric limits. The limits depend on the
implementation. The current implementation for Integer and Real is based on Java [3] and
thus has the same limits as the corresponding Java types which are java.lang.Integer and
java.lang.Double.
NumericType * NumericType : NumericType
The multiplication of two numeric values.
NumericType + NumericType : NumericType
The addition of two numeric values.
NumericType - NumericType : NumericType
The substraction of two numeric values.
- NumericType : NumericType
The negative numeric value.
NumericType / NumericType : NumericType
NumericType.div( NumericType ) : NumericType
The division of two numeric values.
NumericType.sin() : NumericType
The sinus of a numeric value.
NumericType.cos() : NumericType
The cosinus of a numeric value.
NumericType.floor() : NumericType
The largest numeric value which is less or equal than the numeric value.
NumericType.max( NumericType ) : NumericType
The maximum of the two numeric values.
NumericType.min( NumericType ) : NumericType
The minimum of the two numeric values.
NumericType.cos() : NumericType
The absolute numeric value.
Collection.sum(): NumericType
The sum of all numeric values.
NumericType.mod( NumericType ) : NumericType
The result of modulo of the first numeric value with the second.
NumericType.round() : Integer
The Integer value that is closet to the numeric value. Halve values are rounded up.
Page 10
4.3.3.1 Integer
An Integer is a whole number. Integer literal examples are 2 and 123. Integer is the
supertype of Real.
Integer has the operations:
IntegerOperation : one of
NumericOperation
4.3.3.2 Real
A Real is a number that may have a fractional part, an exponent, and a type suffix. Examples
of Reals are 5e5f and -3.12.
Real has the operations:
IntegerOperation : one of
IntegerOperation
4.4 Collections
Collection is the abstract superclass of Set, OrderedSet, Bag and Sequence.
Sequence{ 1, 2, 3, 4, 5, 6, 7, 8 }
Sequence{ 1..(4 + 4) }
Sequence{ 1..8 }
4.4.1 Set
Set inherits all collection operations. Additionally, set has the following set specific
operations:
Set.union( Set ) : Set
The union of the first and the second set.
Set.union( Bag ) : Bag
The union of the set and the first bag.
Set = Set : Boolean
Tests if the sets contain the same elements and if this is true it returns true.
Set.intersection( Set ) : Set
The intersection of the first and the second set.
Set. intersection( Bag ) : Bag
Page 12
4.4.2 OrderedSet
Ordered set inherits all collection operations. Additionally, ordered set has the following
ordered set specific operations:
OrderedSet append( Object ) : OrderedSet
Appends the object at the end of the ordered set.
OrderedSet prepend( Object ) : OrderedSet
Inserts the object at the first place of the ordered set.
OrderedSet insertAt( Integer, Object ) : OrderedSet
Inserts the object at the place indicated by the Integer value in the ordered set.
OrderedSet subOrderedSet ( Integer, Integer ) : OrderedSet
All elements starting at the first Integer value and including the second Integer value.
Page 13
4.4.3 Bag
Bag inherits all collection operations. Additionally, bag has the following bag specific
operations:
Bag.union( Bag ) : Bag
The union of the first and the second bag.
Bag.union( Set ) : Bag
The union of the set and the first bag.
Bag = Bag : Boolean
Tests if the bags contain the same elements the same number of times and if this is true, it
returns true.
Bag.intersection( Bag ) : Bag
The intersection of the first and the second bag.
Bag. intersection( Set ) : Set
The intersection of the bag and the first set.
Bag including( Object ) : Bag
Adds the object to the bag.
Bag excluding( Object ) : Bag
Removes all occurrences of the given object from the bag.
Bag count( Object ) : Integer
The number of occurrences of object in the bag.
Bag flatten() : Bag
If the elements of the bag are not collections the bag will be returned unmodified. If the
elements in the bag are collections, the returned bag will directly contain all elements of those
collections.
Bag asSet() : Set
Casts the bag to a set. This removes all duplicates.
Page 14
4.4.4 Sequence
Sequence inherits all collection operations. Additionally, sequence has the following sequence
specific operations:
Sequence count( Object ) : Integer
The number of occurrences of object in the Sequence.
Sequence = Sequence : Boolean
Tests if the sequences contain the same elements in the same order and if this is true, it returns
true.
Sequence.union( Sequence ) : Sequence
Appends the second sequence to the first sequence.
Sequence flatten() : Sequence
If the elements of the sequence are not collections the sequence will be returned unmodified.
If the elements in the sequence are collections, the returned sequence will directly contain all
elements of those collections.
Sequence append( Object ) : Sequence
Appends the object at the end of the sequence.
Sequence prepend( Object ) : Sequence
Inserts the object at the first place of the sequence.
Sequence insertAt( Integer, Object ) : Sequence
Inserts the object at the place indicated by the Integer value in the sequence.
Sequence subSequence ( Integer, Integer ) : Sequence
All elements starting at the first Integer value and including the second Integer value.
Sequence at( Integer ) : Object
Returns the object at the position indicated by the Integer value in the sequence.
Sequence indexOf( Object ) : Integer
Returns the position of the object in the sequence.
Sequence first( Integer ) : Object
Returns the first object of the sequence.
Sequence last( Integer ) : Object
Page 15
4.4.5.1 Collection
There is a rich set of iterator expressions defined on collection.
exists
If body evaluates to true for at least one element in the source collection, the exists expression
returns true, otherwise false.
forAll
If body evaluates to true for at all elements in the source collection, the forAll expression
returns true, otherwise false.
isUnique
If body expression evaluates for each element in the source collection a different value, the
isUnique expression returns true, otherwise false.
any
Returns any element in the source collection for which body evaluates to true.
one
If body evaluates to true for exactly one element in the source collection, the one expression
returns true, otherwise false.
collect
The collect expression returns the collection of elements which results from applying body to
every member of the source set. The result is flattened.
Page 16
4.4.5.2 Set
Set allows the iterator expressions defined on collection and additionally it defined some set
specific ones.
select
The subset of set for which the body evaluates to true.
reject
The subset of set for which the body evaluates to false.
collectNested
Returns the bag of elements which results from applying body to every member of the source
set.
sortedBy
Returns the Set as an ordered set, lower values go first. The elements of the set must be
comparable with<.
4.4.5.3 Bag
Bag allows the iterator expressions defined on collection and additionally it defined some bag
specific ones.
select
The subset of bag for which the body evaluates to true.
reject
The subset of bag for which the body evaluates to false.
collectNested
Returns the bag of elements which results from applying body to every member of the source
bag.
sortedBy
Returns the bag as a sequence with lower values first. The elements of the bag must be
comparable with<.
4.4.5.4 Sequence
Sequence allows the iterator expressions defined on collection and additionally it defined
some sequence specific ones.
Bag allows the iterator expressions defined on collection and additionally it defined some bag
specific ones.
select
The subset of sequence for which the body evaluates to true.
reject
The subset of sequence for which the body evaluates to false.
collectNested
Page 17
4.5 Tuples
Tuples are known from mathematics and database theory. An n-tuple is a composite with n
elements.
TupleLiteral :
Tuple { TupleElements }
TupleElements :
TupeElementopt
TupeElements , TupeElement
TupleElement :
Identifier = Expression
4.6 Enumerations
In ATL programs model enumerations are defined by the source and target metamodels.
Enumerations cannot be defined in ATL programs themselves.
5 ATL Programs
ATL has three different types of programming units, namely modules, queries and libraries.
Modules transform models to models while queries do model to text transformations.
Libraries serve to define repetitive pieces of code in one place. In contrast to queries and
modules, libraries are not executable on their own.
5.1 Modules
The primary intention of ATL is model to model transformation and thus modules are the
most common ATL programs. A module consists of a header section and in some cases of an
import section. These are followed by zero to n helpers and rules. Best programming practice
is to write the all helpers before the rules, but this is not obligatory.
Module :
HeaderSection ImportSectionopt RulesAndHelpers
RulesAndHelpers :
RulesAndHelpersopt Helperopt
RulesAndHelpersopt Ruleopt
Page 18
Please note that the identifier should/must correspond to the modules file name.
5.2 Queries
Queries allow to analyse models and to calculate an output that is not necessarily a model.
This makes them very useful to generate text or code from a model.
Query :
query Identifier = Expression ; Helpers ImportSection
query Identifier = Expression ; ImportSection Helpers
Helpers :
Helperopt Helpersopt
5.3 Libraries
Libraries are reusable program units that can be called from modules or from queries.
Library :
library Identifier; ImportSection Helpers
Helpers :
Helperopt Helpersopt
It is important to mention that if a module imports a library this has to be declared in the
import section and in the configuration.
Page 19
6 OCL Expressions
OCL [7], the Object Constraint Language, is an OMG standard to express constraints. In ATL
programs OCL expressions are omnipresent which is why they are simply referred to as
expressions. They are used within declarative rules, helpers and queries.
Expression :
any literal
Identifier
IfExpressoin
LetExpression
OperatorExpression
If-expressions have a return value and are thus expressions. The same applies to letexpressions.
VariableName declares the name of the let-variable. The let-variable is of the type specified
(primitive type or collection). It is attributed the value of the first expression. The Letexpression returns the value of the second expression. The visibility and the lifetime of the
let-variable are restricted to the second expression.
7 Helpers
Helpers can be used to define (global) variables and functions. Helper functions are OCL
expressions. They can call each other (recursion is possible) or they can be called from within
rules. In general, they serve to define repetitive pieces of code in one place.
Page 20
8 Declarative Rules
Rules describe the transformation from a source model to a target model by relating
metamodels. Each rule contains a unique name. It is introduced by the keyword rule that is
followed by the rules name. Its implementation is surrounded by curly brackets.
Rule :
rule { from SourcePattern to TargetPattern }
rule { from SourcePattern using { UsingExp } to TargetPattern }
SourcePattern :
Identifier : MetamodelClassPath ( Filter )
Filter :
Expression
UsingExp :
UsingElement
UsingElement UsingExp
UsingElement :
Identifier : Identifier = Expression ;
TargetPattern :
TargetPatternElement
TargetPatternElement , TargetPattern
TargetPatternElement :
Identifier : MetamodelClassPath ( Assignements )
Identifier : distinct MetamodelClassPath
foreach (Identifier in Identifier )
( Assignements )
Assignements :
Assignementopt
Assignement , Assignements
Assignement :
LeftSideElement = RightSideElement
Page 21
LeftSideElement :
Identifier
RightSideElement :
Expression
With using one can define variables for the scope of the rule. Each time the rule is matched
the variables will be recalculated. The using variable (usually a Sequence) can be reused to
define complex target pattern elements with the distinct and the foreach keywords but
also in the context of an assertion. Complex target pattern elements can create a variable
number of output elements, which is different form simple target pattern elements (without
distinct and foreach ) which create only one target element.
An example for a more advanced rule with using has been taken from the geometrical
transformation example explained in [2]. Here it is merely used to illustrate the syntax:
rule Point {
from
point :
DXF1!Point
using {
c : GeoTrans!GeoTransfo = let g : GeoTrans!GeoTransfo =
GeoTrans!GeoTransfo->
allInstances()->
select(t|
t.subGeoTransfos->
size() = 0 )->first()
in g;
}
to
out : DXF2!Point (
name <- point.name,
x <- thisModule.doCommands( point,
point.getPoint(), c ).x,
y <- thisModule.doCommands( point,
point.getPoint(), c ).y,
z <- thisModule.doCommands( point,
point.getPoint(), c ).z
)
}
9 Imperative Constructs
to be written later
10 Execution Semantics
Executing an ATL transformation model requires several steps. If the model is given in
textual format, it is first parsed and transformed to a model defined using the ATL metamodel. This model is then statically checked for semantic errors against the ATL metamodel
and source and target meta-models. The next step can either be an interpretation or a
compilation followed by an execution. In both cases, the application of an ATL
transformation follows the semantics described in this section.
If there is a called rule marked as entrypoint (only one is allowed) it is executed first. This
rule can call any number of called rules until it reaches its end. Then, the matched rules are
Page 22
Page 23
I. References
[1] Allilaire, F., Idrissi, T. ADT: Eclipse Development Tools for ATL. EWMDA-2, September 2004, Kent,
http://www.cs.kent.ac.uk/projects/kmf/mdaworkshop/
[2] ATLAS Group, ATL Transformation Example: Geometrical Transformations. 2005
[3] Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, Second Edition. Addison Wesley, 2000
[4] IBM, Eclipse project, EMF Documentation. http://www.eclipse.org/emf/
[5] OMG/MOF Meta Object Facility (MOF) Specification. OMG document AD/97-08-14, September 1997.
http://www.omg.org
[6] OMG/RFP/QVT MOF 2.0 Query/Views/Transformations RFP. OMG document AD/2002-04-10.
http://www.omg.org
[7] OMG UML 2.0 OCL Specification. OMG document AD/03-01-07 2003
[8] OMG/XMI XML Model Interchange (XMI) OMG document AD/98-10-05, October 1998.
http://www.omg.org
[9] The Unicode Consortium. The Unicode Standard, Version 4.0.0, defined by: The Unicode Standard, Version
4.0, Boston, MA, Addison-Wesley, ISBN 0-321-18578-1, 2003
Page 24