logo back up home forward   further reading more topics »

XES - Programmers Guide - nodeBinaryOp

for information about XES schema see these pages.

BinaryOp

The binaryOp node is used to represent an operation on two operands which may be intergers, floating point , boolean or string.

Binary Operation contains two elements plus an operation to be performed on them, The operation is represented by a simple type and this node must contain the 2 elements to be combined, the left hand and right hand operands. In addition any number of comments can be added.

Attributes used

operator must be set to one of || , && , | , ^ , & , == , != , < , > , <= , >= , << , >> , >>> , + , - , * , / , %

Child Elements

There must be exactly two child elements, each one represents an operand (in addition there can be any number of comment nodes).

Each of the two operands can be either:

Schema entry

	<xs:complexType name="binaryOpType">
<xs:sequence minOccurs="2" maxOccurs="unbounded">
<xs:element name="variable" type="variableType"/>
<xs:element name="array" type="arrayType"/>
<xs:element name="constant" type="constantType"/>
<xs:element name="call" type="callType"/>
<xs:element name="binaryOp" type="binaryOpType"/>
<xs:element name="unaryOp" type="unaryOpType"/>
<xs:element name="comment" type="commentType"/>
</xs:sequence>
<xs:attribute name="operator" type="operatorType"/>
</xs:complexType>
<xs:simpleType name="operatorType">
<xs:restriction base="xs:string">
<xs:enumeration value="||"/>
<xs:enumeration value="&amp;&amp;"/>
<xs:enumeration value="|"/>
<xs:enumeration value="^"/>
<xs:enumeration value="&amp;"/>
<xs:enumeration value="=="/>
<xs:enumeration value="!="/>
<xs:enumeration value="&lt;"/>
<xs:enumeration value="&gt;"/>
<xs:enumeration value="&lt;="/>
<xs:enumeration value="&gt;="/>
<xs:enumeration value="&lt;&lt;"/>
<xs:enumeration value="&gt;&gt;"/>
<xs:enumeration value="&gt;&gt;&gt;"/>
<xs:enumeration value="+"/>
<xs:enumeration value="-"/>
<xs:enumeration value="*"/>
<xs:enumeration value="/"/>
<xs:enumeration value="%"/>
</xs:restriction>
</xs:simpleType>

Translation to other languages

In XES the precedence of operations is determined by the way that the binaryOp nodes are nested, so there is no need for explicit coding of brackets. However when converting from XES to java we have to use brackets when required, this is determined by the rules of precedence. Since this would be complicated to implement, as a first stage it is good enough to always wrap inner operations in brackets even though this may not always be necessary. Athough we should not wrap the outer most operation in brackets.

Possible Improvements

 

Examples of usage

usage java example XES example
  a = b || c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="||">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b && c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&amp;&amp;">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b | c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="|">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b ^ c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="^">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b & c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&amp;">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b == c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="==">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b != c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="!=">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b < c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&lt;">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b > c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&gt;">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b <= c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&lt;=">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b >= c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&gt;=">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b << c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&lt;&lt;">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b >> c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&gt;&gt;">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b >>> c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="&gt;&gt;&gt;">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b + c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="+">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b - c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="-">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b * c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="*">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b / c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="/">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b % c ; <assign operator="=">
<variable name="a"/>
<binaryOp operator="%">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</assign>
  a = b + c * d; <assign operator="=">
<variable name="a"/>
<binaryOp operator="+">
<variable name="b"/>
<binaryOp operator="*">
<variable name="c"/>
<variable name="d"/>
</binaryOp>
</binaryOp>
</assign>
  a = c * d + b; <assign operator="=">
<variable name="a"/>
<binaryOp operator="+">
<binaryOp operator="*">
<variable name="c"/>
<variable name="d"/>
</binaryOp>
<variable name="b"/>
</binaryOp>
</assign>
  a = (b + c) * d; <assign operator="=">
<variable name="a"/>
<binaryOp operator="*">
<variable>
<binaryOp operator="+">
<variable name="b"/>
<variable name="c"/>
</binaryOp>
</variable>
<variable name="d"/>
</binaryOp>
</assign>
  a = c * (d + b); <assign operator="=">
<variable name="a"/>
<binaryOp operator="*">
<variable name="c"/>
<variable>
<binaryOp operator="+">
<variable name="d"/>
<variable name="b"/>
</binaryOp>
</variable>
</binaryOp>
</assign>
     

metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover Processing XML with Java: A Guide to SAX, DOM, JDOM, JAXP, and TrAX

Other Java books

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to this site, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

cover JBuilder - There is also a free version of Jbuilder at borland website . However its licence conditions are quite restrictive so you may prefer another java IDE.

Can this page be improved?

Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page.

 

progam

I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here:

for xml encoding: http://sourceforge.net/projects/xes/

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

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