Expression Pattern Language (eXPL)

Exressions

Expressions are phrased using words, numbers and symbols to perform logical and functional operations. Expressions consist of identifiers, literals and operators. There is also one keyword, regex, which is introduced in Regular Expressions below.

Identifers

Identifiers in eXPL follow the Java naming syntax: identifiers begin with an alpha character which is followed by any number of alpha or numeric characters or underscore. You see in all the eXPL examples a naming convention different from Java's camelCase. The convention is intended to make eXPL look different from Java and uses all lower-case names, with underscore character used to separate words.

It is normal for an identifier to occupy a space isolated from all identifiers outside the space. Such name spaces avoids the difficulty of maintaining one global space where all names must be unique. There is, however, one global namespace accessible from all other name spaces. An eXPL name space is called a scope. A template is also a name space within a scope and thus there is a need to distiguish not only between scopes, but also between templates in the same scope. The answer is to have multi-part names consisting of identifiers separated by a period character eg. "freight.city" from a previous example.

Literals

Literals represent data values. Java syntax for literals is followed for strings and numbers, but character literals are not supported. Sets of literals can be placed in {} braces next to a variable to indicate "match any any literal in the set". Also used in eXPL are "true", "false", "unkown" and "NaN" (not a number).1

  1. Literals - "NaN" in any numeric calculation results in NaN.

Variables

A variable is set either at compilation of the eXPL script or during execution of a query. It's visibility depends on the context in which it is declared. Variables declared in the global scope are the most visible. A variable declared in one a template is visible in another template in the same scope by using a two-part name, the first part being the template name and the second part being the variable name eg. "account.name". Note that the topic of scopes appears toward the end of this reference because the majority of eXPL features can be demonstrated in the global scope.

Operators

eXPL follows Java's use of symbolic operators in expressions except the ternary operators ? : which still have a logic control role, but are used separately and trigger a short circuit 1. Operator ? is "short circuit on false" and operator : is "short circuit on true". Java precedence also applies along with the use of parentheses to override precedence.

{} Set Selection

The {} operator is used to enclose a set of literals which defines the allowed values for an associated variable. The logic is reversed by placing a ! character in front of the list. See the EuropeanMegaCities application in tutorial 4 demonstrating the set operator used to select from cities in continent Europe by eliminating all the other continents.

Here are some other operators specific to eXPL. Note that some operators have a dual use depending on context:

OperatorDescription
.Placed on left of term to hide it
->Query chain right/Select term by name
<-Query chain left
[]Index any list
[].Index axiom list & select term by name
[][]Index axiom list & select term by index

Go to provided links for more information on these operators.

Number Type Conversion

There is no operator associated with type conversion as it is an operation that occurs automatically. Mathematical expressions may contain numbers of mixed types, which forces implicit type convsersion to occur during evaluation. The strategy employed is avoid loss of information. For example, if multiplying a percent value such as 4.5% by an amount represented as integer 1234, the result with integer arithmetic is 0, not 56. So when an integer and double are paired in an operation, the integer is converted to a double. When a decimal (or currency) is involved in an operation then, if necessary, the other term is converted to a decimal. Type conversion can be achieved explicitly using assignment to a variable that has been declared to be of the desired type.

String to number type or currency conversion also occurs automatically, with the text parsed according to the prevailing locale. An example can be seen in the Lists application of tutorial3:

list<decimal> huges = { "9,223,372,036,854,775,808"...

Expression Example

Application Expressions of tutorial4 demonstrates some simple expressions. Here are the expressions being tested:

integer x = 1;
integer y = 2;
x + y == 3,
y - x == 1,
x * y == 2,
6 / y == 3,
(y + 1) * 2 > x * 5,
(y *= 3) == 6 && y == 6

You can experiment by adding your own expressions to confirm there are no surprises.

  1. Short circuiting reverses execution to the point the last axiom was read and then moves forward again after reading the next axiom