XES - Schema Example

The aim of this page is to propose an XML encoding for source code. This is to enable simpler translation between different language source code, code generators and XMI.

Variables, declaration and assign.

Variables may be defined, initialised and used in the same statement or in seperate statements. Any variables may also be used in arrays.

All of these things are based on variable node, even assignment will allways have a varible on the left hand side.

When a variable is used we need a quick way to link it back to its definition, how do we define such a link? we need to do this both for local variables, class varibles and varibles in other classes, how do we implement late binding of variables?

Should all node names be expanded out to their full path name?

Java example   XES
int var1;
     
<variable name="var1"/>
var1 = 1;
<variable name="var1">
  <assign operator="=">
    <constant intConst="1"/>
  </assign>
</variable>
int var2 =2;
<variable name="var2.2"/>
int[] array1;
<variable name="array1" type="int" array="true"/>
array1 = new int[1];
<variable name="array1">
  <assign operator="=">
    <array>
      <constant intConst="1"/>
    </array>
  </assign>
</variable>
array1[0]=3;
<variable name="array1">
  <array>
    <constant intConst="0"/>
  </array>
  <assign operator="=">
    <constant intConst="3"/>
  </assign>
</variable>
int[] array2=new int[2];
<variable name="array2" type="int" array="true">
  <array>
    <constant intConst="2"/>
  </array>
</variable>
double x,y,z;
is:
<variable name="x.y.z"/>
should be:
<declare type=double>x</declare>
         <declare type=double>y</declare>
         <declare type=double>z</declare>

JDK 1.5 allows Generic Types:

ArrayList<Integer> list = new ArrayList<Integer>();

JDK 1.5 also allows enum:

public enum StopLight { red, amber, green };

 
<assign name="list" declare="ArrayList" generic="Integer">
  ArrayList
</assign>
<declare type=enum values="red, amber, green">
  StopLight
</declare>
String values[] = (String []) names;  

<assign name="values" declare="String" array=true>(String []) names</assign>

other possible parameters:

type = "=" default
type = "++pre"
type = "++post"
type = "--pre"
type = "--post"
type = "+="
type = "-="
type = "*="
type = "/="
type = "%="
type = "&="
type = "|="
type = "^="
type = "<<="
type = ">>="
type = "<<<="

     
     

Comment

Java example XES
/* text */
// one line comment

<comment>text</comment>

(each line held in separate<comment> tags

Class Declaration

Java example XES
/** class meta description */
class date extends Object {
...
}

<classdec name="date" extends="Object" meta="text description"> ...parameters ... methods ...</classdec>

other parameters:

abstract=true

JDK 1.5 allows metadata following @ sign

@meta class date extends Object {
...
}

 

Class Call

this needs more work as class call could occur anywhere in the right hand side of equation

Java example XES
date d = new date(day,month,year); <class name="date"> <param/ name="day"> <param/ name="month"> <param/ name="year"></class>

Method Declaration

Java example XES

/** move to a point on screen
* @param x how far from left of screen
* @param y how far from bottom of screen
* @returns successful did it work*/
public boolean move(int x,int y){

body

}

<methoddec name="move" tag="move to a point on screen">
<param name="x" type="int" tag="how far from left of screen">
<param name="y" type="int" tag="how far from bottom of screen">
...body ...
</methoddec>

other parameters:

public=true
protected=true
private=true
final=true
synchronised=true
native=true

Support for javadoc style tags
possible tags are:

@author classes and interfaces only
@version classes and interfaces only
@param methods and constructors only)
@return methods only)
@exception (@throws is a synonym added in Javadoc 1.2)
@see
@since
@serial (or @serialField or @serialData)
@deprecated

 

JDK 1.5 allows metadata following @ sign

@meta public boolean move(int x,int y){

body

}

<methoddec name="move" metadata="meta">

Method Call

This is part of assignment (or can be) but I think it is important that method calls are structured so that it is easier to process the structured data to convert to other languages and to make sure that calls link to declarations. So we need to do more work on the structuring of right hand side of equations.

Java example XES
result = move(10,20);

<assign result="values">
<call name="move"><param="10"><param="20">
</call>
</assign>

Package Declare

Java example XES
package myprogram; <package name="myprogram"/>

Package Import

Java example XES
import java.io.DataInputStream; <import package="java.io" classname="DataInputStream"/>

Interface Declare

Java example XES

/** class meta description */
interface pressEvent {
...
}

<interfacedec name="pressEvent" > ... methods ...</classdec>

other parameters:

abstact=true
extends="name"
public=true

Conditionals

Java example XES

if (a==0)

else

switch (a) {
case 0 : ...
case 1 : ...
default: ...
}

<if> <test>a==0</test>... <else/> ... </if>

<switch variable="a">
<case value=0> ... </case>
<case value=1> ... </case>
<default> ... </default>
</switch>

Loops

XES has only one loop type, the java loop types (for, while, do) map to loop by using different combinations of:

loop has a attribute 'code' which can be (for, while, do) which specifies which combination of (initialise, operation, pre-condition, post-condition) elements are expected between this node. This seems a bit restictave and specific, can anyone think of a better way to specify which subnodes are initialise, operation, pre-condition or post-condition?

Java example   XES
for (int i=0;i<3;i++) {
  break;
}
<loop code="for">
  <variable name="i.0"/>
  <binaryOp operator="&lt;">
    <variable name="i"/>
    <constant intConst="3"/>
  </binaryOp>
  <call name="i"/>
  <block>
    <break/>
  </block>
</loop>
while (true) {
  break;
}
<loop code="while">
  <constant boolConst="true"/>
  <block>
    <break/>
  </block>
</loop>
do {
  break;
} while (true);
<loop code="do">
  <block>
    <break/>
  </block>
  <constant boolConst="true"/>
</loop>

JDK 1.5 allows enhanced for loop:

for (Integer i : list)

   

Exceptions

Java example XES

try {

} catch () {

}

<try>
<catch>
</try>


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.