Skip to content

Expression elements

MaartenHilferink edited this page Sep 16, 2026 · 1 revision

A calculation rule, the expression after := of a tree item, is built from three kinds of elements: literals, applications of operators and functions, and references to other tree items. This page describes each kind and the notation that combines them; Expression syntax describes where a rule is written, Operator gives the precedence of the operator symbols and Operators and functions lists the functions.

attribute<float64> dist_km (Road) := sqrt(sqr(Node/x[F1] - Node/x[F2]) + sqr(Node/y[F1] - Node/y[F2])) / 1000.0;

In this rule sqrt, sqr and -, +, / are function and operator applications, Node/x, Node/y, F1 and F2 are item references, and 1000.0 is a literal.

literals

A literal is a value written as such: 42 (a uint32), 2.5 (a float64), 2.5f (a float32), %FF (255), 5[m] (5 in the unit m) or 'Amsterdam'. The notation, the suffixes that select a value type and the escape codes of strings are on Literal. There are no boolean, null or point literals: true, false and null_f are constant functions, points are made with point_xy.

operator applications

An operator is a symbol applied to one or two operands: a + b, -a, a == b, cond ? a : b. The complete table with the precedence order and the function each symbol stands for is on Operator; a + b is add(a, b), and either notation may be used. Notes on the notation:

  • Arithmetic + - * / % ^. Write a division with spaces around the slash: a / b. Without them, a/b is read as the path of an item b in container a, and reported as Unknown identifier 'a/b'. Between two literals no spaces are needed, 6.0/3.0 is a division.
  • Comparison == != < <= > >=, with = accepted for == and <> for !=.
  • Logical && || !, with the words and and or accepted for && and ||. Unary ! binds weaker than a comparison: !a == b means !(a == b), and a == !b is a syntax error; write a == (!b).
  • Conditional cond ? a : b, the iif function; it nests to the right, a ? b : c ? d : e is a ? b : (c ? d : e).
  • Unary minus applied to an unsigned value gives the signed type of the same width: -1 is an int32, since 1 is a uint32.
  • # before a unit is its number of elements: #Region is nrofrows(Region).
  • a[b] is lookup(b, a) when b is a relation and value(a, b) when b is a unit: Region/name[City/Region_rel] gives each city the name of its region, 42195[meter] is a length.
  • rel -> a is the same lookup written in reading order: City/Region_rel -> name finds name in the values unit of the relation, so the container of name need not be repeated.

Parentheses group: (a + b) * c. Whitespace, line breaks and comments (// to the end of the line and /* between */) are allowed anywhere between elements, also in the middle of a rule that runs over several lines.

function applications

A function is applied by name, with its arguments in parentheses, separated by commas: sum(City/NrInhabitants, City/Region_rel), pi(). Applications nest, and a function may be an argument's value as well as the rule's outer element. The names are those of the operators and functions, and, since GeoDMS 20.9.0, of the functions defined in the configuration itself; names are case insensitive, but the engine registers its own names in lower case and reports a spelling that differs in case as a case mix-up.

The arguments of a function are expressions themselves, so any of the three element kinds may appear there. Since GeoDMS 20.9.0 a function can be an argument as well, see Generic function and map; the apply and instantiate keywords in front of an application are described on Function definition.

item references

A reference is the name of another tree item, and it stands for what that item is: the data of a data item, the unit itself for a unit, the container for a container. The rules for finding the item by its name are on NameSpace; in short:

  • A plain name, flow, is searched from the container of the item being defined, upwards through its parents, and through the containers named in a Using property.
  • A path, Units/m or Road/geometry, names the first part that way and then descends: the parts after the first must be direct subitems. This is the form to reach an item in another branch.
  • A path that starts with / starts at the root of the configuration: /Units/m. The root is the outermost container itself, so its own name is not part of such a path, exactly as in the item names given to GeoDMSRun.
  • . is the container of the item being defined and .. its parent, see Parent item: id(.) is the id of the domain unit in whose block an attribute is declared, and ../m an item next to that container.

Item names are case insensitive, Flow and flow are the same item, but a spelling that differs from the one at the declaration is reported, see Tree item name.

A reference to an attribute of another domain unit is allowed only through a relation, with [ ], -> or lookup; a rule that mixes attributes of different domains directly is refused with a domain mismatch. A parameter, whose domain is void, combines with an attribute of any domain.

indirect expressions

A rule that starts with = is an indirect expression: the expression after = is evaluated to a string, and that string is then parsed as the actual calculation rule. Item references and literals in it build the text of the rule rather than take part in the calculation, which is how a rule can depend on a parameter, a year or a file name.

see also

Clone this wiki locally