Template-Axiom-Query (TAQ)

Expressions

Expressions are constructed using literals, variables and object methods, either singly, or in combination connected by symbolic operators to which precedence applies. TAQ adopts almost all Java's operators and operator precedence. Missing are ""instanceof and ""ternary"". However, the TAQ '?' and ":' operators are used in a way that echoes Hava's ternary operator.

Special Operators

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

OperatorContextDescription
?axiom termBlank place holder
?template termCriterion
?:template termConverse criterion
->queryChain to right
->template termSelect term by name

Literals

Literals represent values of the supported types. TAQ literals follow Java for strings, numbers and boolean "true" and "false". Character literals are not supported. Also TAQ has unknown for an empty variable declared without being assigned a type and NaN* for ""not a number"".

Any numeric expression that fails, for example divide by zero, results in a value of NaN.

Variables

All variables are operands designed to participate in a template's unification and evaluation cycles. A variable is set either at compilation time meaning it is a literal, or during execution of a query. For every expression operator a special operand called an "Evaluator" is created which facilitates evaluation. Any non-trivial expression therefore ends up as an operand graph with an Evaluator at each node.

A list variable may reference the list itself or a list item, Consider the following axiom list containing 4 high cities that needs to be sorted by elevation

axiom listhigh_cities(city, altitude)
{"addis ababa", 8000}
{"denver", 5280}
{"flagstaff", 6970}
{"leadville", 10200}

Note that a list header has been employed to name both of the terms in each list item. The first axiom in the list with city "addis abada" is referenced by variable high_cities[0]. The right arrow '->' selects an axiom term by name. Hence high_cities[0]->altitude is a variable with value 8000. To iterate through the list, use an incrementing index such as [i++] where i is an integer initialized to zero.

Number Type Conversion

Type conversion occurs automatically when two numbers of different types interact. There is no explicit type casting as in Java. Mathematical expressions may contain numbers of mixed types, which forces implicit type conversion 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 is setting an integer to the maximum positive value, which is a very big number given integer in TAQ is 64 bit

integer max_integer "9,223,372,036,854,775,808"

Note that the number format needs to be adjusted according to locale.

Expression Example

expressions.taq demonstrates some simple expressions. Here are the expressions being tested:

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.