For information about XES schema see these pages.
Variable
The variable node is used to define a variable, for example:
int myVariable;
Or to allocate a value to a variable, for example:
myVariable = 0;
Or to use the value of a variable, for example:
otherVariable = myVariable;
Or a combination of these, for instance:
int myVariable = 0;
Attributes used
Attribute "name" must always be set in the variable node.
Attribute "type" must always be set if the variable is being defined, so presence of the type attribute marks this as a variable definition. Attributes "public" , "private" , "protected", "static", "primitive" and "array" may optionally be used in a definition (and only a definition) node.
Child Elements
The only child elements allowed are "comment" , "array" and "assign".
Array node is used when we are operating on an array and we want to specify a particular index.
Assign node is used when we assign a value to the variable.
In order to assign a value to the variable we use two node types, variable and assign, currently we allow two ways to do this,
If we have the following equation:
variable = expression;
The left hand side (lhs) always specifies a variable. The right hand side (rhs) may be any node or node tree containing nodes that return a value. The two ways of representing this are either,
nodeAssign +-- nodeVariable // lhs +-- expression // rhs
Or,
nodeVariable // lhs +-- nodeAssign +-- expression // rhs
I think allowing two possible syntax's is potentially confusing and that the nodeAssign is not necessary and that the equation can be represented much more simply and unambiguously as follows:
nodeVariable // lhs +-- expression // rhs
In this case nodeVariable would have the attributes that were previously part of nodeAssign in addition to its current attributes.
Schema entry
<xs:complexType name="variableType">
<xs:sequence>
<xs:element name="comment" type="commentType"/>
<xs:element name="assign" type="assignType"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="public" type="xs:boolean"/>
<xs:attribute name="private" type="xs:boolean"/>
<xs:attribute name="protected" type="xs:boolean"/>
<xs:attribute name="static" type="xs:boolean"/>
<xs:attribute name="primative" type="xs:boolean"/>
<xs:attribute name="array" type="xs:boolean"/>
</xs:complexType>
Possible Improvements
There is a possible change which could be made as described here.
Should we have different node types for variable definition and variable usage?
Currently XES has a variable entity and if its type
attribute is not set then it is defined elsewhere. I think it is worth thinking
through the option of using different node types.
For instance a variable defined as follows:
int i;
would be coded as a variableDefinition entity which would have name
and type attributes.
When the variable is used:
i = 0;
this would be coded as a variable entity which would have name
but no type attribute.
If the variable is defined and used in the same line:
int i = 0;
Then when this is encoded then we would have to create both a variableDefinition
entity and a variable entity.
The disadvantage of this is that it takes up more space, but I dont think
people will type in XES by hand, so this may not be a disadvantage. It seems
to me that the advantage of this is that it separates different functions and
makes it easier to pull out all the definition information, it also means it
is used in a similar way regardless of where the variable is defined.
I think that, before we can decide this, we need to decide whether XES should
add information to resolve names. In other words, when a variable is used, should
it hold a path attribute to where that variable is defined. Perhaps in OOP this
is only known at runtime but at least we could point to the base definition?