XES - Programmers Guide - nodeVariable

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 don’t 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?

Examples of usage

usage java example XES example
Variable definition int i;

<variable name="i" type="int"/>

Setting a variable.

i=0;

<assign operator="=">
<variable name="i"/>
<constant intConst="0"/>
</assign>

I think it would be better to change the XES standard to code this as:

<variable name="i" operator="=">
<constant intConst="0"/>
</variable>

variable definition and assignment.

int i=3;

<variable name="i" type="int">
<assign operator="=">
<constant intConst="3"/>
</assign>
</variable>

Increment or decrement a variable. i++;

<unaryOp operator="++">
<variable name="i"/>
</unaryOp>

currently there is a bug which codes this as:

<assign operator="=">
<variable name="i"/>
<unaryOp operator="++" preOp="true"/>
</assign>

pre Increment or decrement a variable. ++i;

<unaryOp operator="++">
<variable name="i"/>
</unaryOp>

Define and set a variable in same statement. int j=1;

<variable name="j" type="int">
<assign operator="=">
<constant intConst="1"/>
</assign>
</variable>

I think it would be better to change the XES standard to code this as:

<variable name="j" type="int" operator="=">
<constant intConst="1"/>
</variable>

Increment and use variable name in same statement. j = i++;

<assign operator="=">
<variable name="j"/>
<unaryOp operator="++" preOp="true">
<variable name="i"/>
</unaryOp>
</assign>

I think it would be better to change the XES standard to code this as:

<variable name="j" operator="=">
<unaryOp operator="++" preOp="true">
<variable name="i"/>
</unaryOp>
</variable>

preIncrement and use variable name in same statement. j = ++i;

<assign operator="=">
<variable name="j"/>
<unaryOp operator="++">
<variable name="i"/>
</unaryOp>
</assign>

Declaring an array int[] k;
<variable isArray="true" name="k" type="int"/>

Creating an array

This coding,using a 'call' node,does not look correct. It would be workable for int since a class name should not be a key word but I dont think this would work for non-native arrays.

k=new int[5];

<variable name="k" operator="=">
<array new=" true" type="int">
<constant intConst="5"/>
</array>
</variable>

currently there is a bug which codes this as:

<variable name="k">
<assign operator="=">
<call new=" new " type="int">
<constant intConst="5"/>
</call>
</assign>
</variable>

Declaring and creating an array int[] m = new int[5];

<variable isArray="true" name="m" type="int" operator="=">
<array new=" true" type="int">
<constant intConst="5"/>
</array>
</variable>

currently there is a bug which codes this as:

<variable isArray="true" name="m" type="int">
<assign operator="=">
<call new=" new " type="int">
<constant intConst="5"/>
</call>
</assign>
</variable>
Initialising or setting array values. m[0] =2;
<assign operator="=">
<variable name="m">
<array>
<constant intConst="0"/>
</array>
</variable>
<constant intConst="2"/>
</assign>
  k[1] = m[0];
<assign operator="=">
<variable name="k">
<array>
<constant intConst="1"/>
</array>
</variable>
<variable name="m">
<array>
<constant intConst="0"/>
</array>
</variable>
</assign>
  myclass n;
<variable name="n" type="myclass"/>
  n = new myclass();
<assign operator="=">
<variable name="n"/>
<call name="myclass" new=" new "/>
</assign>
  otherclass p=new otherclass();
<variable name="p" type="otherclass">
<assign operator="=">
<call name="otherclass" new=" new "/>
</assign>
</variable>
  myclass.myvalue=3;
<assign operator="=">
<variable name="myclass.myvalue"/>
<constant intConst="3"/>
</assign>
  myclass.mymethod(); <call name="myclass.mymethod"/>
     
     
     
     
     
     

 

Mapping to other languages

Modifiers

XES java C# C++
  public public  
  protected protected  
  private private  
    abstract  
  static    
  final    
  transient    
  volatile new  
    internal  
    sealed  
    unsafe  
       
       

Java

int myVariable = 0;
myVariable = 1;

Scala

var myVariable = 0;
myVariable = 1;

metadata block
see also:

 

Correspondence about this page

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.