Description of Expression Language Syntax and Semantics

An expression is a task on formula calculation. The expression value is a calculation result. The expression is built out of constants, objects and their properties and methods, operators, function callings and round brackets.

Data types used:

  • All data types, available in .NET framework, are used in the expressions. Also there is a special support for integer-valued, fractional, logical values, strings and vectors.
  • The PerpetuumSoft.Framework.Drawing.Vector data type is used for vectors.

The following operations are available in expressions:

Arithmetic operations

  • ‘+’ – addition. It is defined for numerical values and vectors.
  • ‘-’ – subtraction. It is defined for numerical values and vectors.
  • ‘-’ – unary minus. It is defined for numerical values.
  • ‘*’ – multiplication. Numerical values and vectors can be the first argument, the numerical value should be the second argument.
  • ‘/’ – division. It is defined for numerical values.
  • ‘%’ – residue of division. It is defined for numerical values.

Logical operations

  • ‘or’ – logical OR. It is defined for logical values;
  • ‘and’ – logical AND. It is defined for logical values;
  • ‘=’ – equals. It is defined for numerical, logical values and vectors;
  • ‘! =’ – inequality. It is defined for numerical, logical values and vectors;
  • ‘<’ – less. It is defined for numerical values;
  • ‘<=’ – less or equal. It is defined for numerical values.
  • ‘>=’ – more or equal. It is defined for numerical values.
  • ‘>’ – more. It is defined for numerical values.
  • ‘not’ – logical negation. It is defined for logical values.

Operations over strings

‘&’ – strings concatenation. It is defined for string values.

Constants assigning

<decimal figure>* - the whole value.

<decimal figure>*.<decimal figure>* - value.

For example, 1234 is the whole, 1234.1234 is the fractional value.

For assigning the linear size in generally accepted units the appropriate postfixes at the end of numerical constant are used.

  • “in” – value in inches
  • “mm” – value in millimeters
  • “cm” – value in centimeters
  • “pt” – value in 1/72 inch points
  • “px” – value in pixels

String constants are assigned with the help of double apostrophes.

For example: “It is a string value”.

The vector is assigned with the help of “[” and “]”.

[<numerical value>,< numerical value>] – vector assigning.

Logical constants are assigned with the help of two key words: ‘true’ and ‘false’.

Access to variables, objects, their fields and methods.

In the expressions, you can apply to variables, available in the instrument by their names. The search of variables and objects by their names is executed in the following way: if an address by the object’s name is present in an expression, the GetObject function that should return the desired object is called for the element the given expression is written for. For any element the GetObject function makes the following: the function returns the element itself, in case its name corresponds to the askable one, otherwise it calls GetObject from the parent. Elements-containers execute the search of the desired object through all included elements. Thus, all instrument elements are available in the expressions. For some elements (for example for Slider) the GetObject function returns special variables. According to the rule pointed out above such variables will be available for both element-container and elements included in it.

Special variables

The following special variables are available in the SliderBase element descendants (e.g., the Slider element):

  • value – the double type variable. The current Slider value.
  • hot – the logical type variable. Hot is set to true if the mouse pointer is over an element.
  • pressed – the logical type variable. Pressed is set to true if the mouse button is pressed when the pointer is placed over an element.
  • center – the vector type variable. The point that corresponds to the current Slider value and is distant from the trajectory center at a 0 distance.

The following special variables are available in the Joint element descendants (e.g., the Joint element):

  • JointRadius - radius of a joint
  • JointCenter – the vector type variable. The point that corresponds to the current Joint value and is distant from the trajectory center at a 0 distance.
  • JointTotalAngle - total angle of a joint.
  • JointStartAngle - the angle of degrees measured clockwise from the X-axis to the start point of the joint.

The following special variables are available in the Guide element descendants (e.g., the Guide element):

  • GuideLength - length of a Guide.
  • GuideCenter - center point of a Guide.
  • GuideEndPoint - end point of a Guide.
  • GuideStartPoint - start point of a Guide.

For applying to objects’ fields and methods the point ‘.’ is used.

For example:

Slider1.Value – applying to the Slider1 element Value property.

Slider1.ToString() – the Slider1 element ToString() method call.

Line1.StartPoint.Rotate(30) – the call of Line1 element StartPoint property Rotate method.

[10, 20].Rotate(30).X – X vector coordination [20, 30], rotated on 30 degrees receiving

ATTENTION! It is impossible to call the object methods, if they are overloaded.

As the expression language is not typified, it is impossible to define what method should be invoked.

In the expressions, you can apply to the functions available in the instrument by their names. The search is executed similarly to the objects search by the names.

The following functions are available for any elements:

The functions of conditional choice

  • if (condition, value1, value2), the 1st parameter should be of logical type; the 2nd and the 3rd parameters should be of object type. If the 1st parameter is true, the function returns the 2nd parameter value, otherwise it returns the 3rd parameter value.
  • switch (condition[0], value[0], … , value by default), if the condition[i] is set to true, the function returns the value[i], if the condition[i] in any i is false, the value returns by default.

Formatting Functions

  • format (object, mask), the object is of object type, the mask is of string type. It returns the object’s string presentation according to the mask.

Mathematical Functions

  • sin(argument) – calculates the argument sine. The argument is of the double type, the calculation result is of the double type.
  • cos(argument) – calculates the argument cosine. The argument is of the double type, the calculation result is of the double type.
  • tan(argument) – calculates the argument tangent. The argument is of the double type, the calculation result is of the double type.
  • atan(argument) – calculates the argument arctangent. The argument is of the double type, the calculation result is of the double type.
  • sqr(argument) – calculates the argument to square. The argument is of the double type, the calculation result is of the double type.
  • sqrt(argument) – calculates the argument’s square root. The argument is of the double type, the calculation result is of the double type.
  • log(argument) – calculates the argument’s natural logarithm. The argument is of the double type, the calculation result is of the double type.
  • exp(argument) – raise E number to the argument degree. The argument is of the double type, the calculation result is of the double type.
  • sign(argument) – returns:-1 if the argument is negative, 0 – if the argument is 0, 1 – if the argument is positive. The argument is of the double type, the calculation result is of the int type.
  • abs(argument) – returns the argument’s absolute value. The argument is of the double type, the calculation result is of the double type.
  • round(argument1, argument2) – rounds the 1st argument value to the symbols amount after the comma, assigned by the 2nd argument. The 1st argument is of the double type, the 2nd argument is of the int type, the calculation result is of the double type.

The expression can be an argument of any function and method. If the expression calculation result is not appropriate to the argument type, the expression will not be calculated.

Date Processing Functions

  • getMonth (argument) – returns the string month name by the date assigned by an argument. An argument should be of the System.DateTime type;
  • getDayOfWeek (argument) – returns the string day of week name by the date assigned by an argument. An argument should be of the System.DateTime type;
  • getQuarter (argument) – returns the quarter number of a date specified as an argument. An argument should be of the System.DateTime type;

Other properties and methods of the System.DateTime type can also be used to get other date values.

The ranking function

  • Range (currentValue, range, zeroPoint) – extracts data intervals. All arguments should be of numeral type. currentValue – the current value; range – the range; zeroPoint – the zero point.

In the expression language the construction for creation of PerpetuumSoft.Framework.Vector type objects is provided. A vector is created with the help of the following construction:

[<expression>, <expression>]. The creation of objects of other types directly in the expression is impossible. But it is possible to realize custom functions, used in the expressions for the objects of desired type creation.

For the SliderBase type elements (for example Slider) and for the elements included in it, the following special functions are available:

  • r(radius) – returns the point, corresponding to the current Slider value and distant from the trajectory center (in which the slider is included) at a radius distance.
  • r(value, radius) – returns the point corresponding to the value and distant from the trajectory center (in which the slider is included) at a radius distance.
  • a() – returns the slider’s rotation angle.

The realization of custom functions and variables, available in the expressions.

In order to make custom functions and variables available in the element expressions, it is necessary to realize a custom element, which will correspondingly realize the PerpetuumSoft.Framework.Expressions.IExpressionSite interface.

After that you need to register your function. It can be done in the following way:

PerpetuumSoft.Framework.Expressions.BuiltInFunctions.RegisterFunction(<Function name>, <inplemented IFunction object>)

Add Feedback