-
Notifications
You must be signed in to change notification settings - Fork 1
Expression elements
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.
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.
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/bis read as the path of an itembin containera, and reported as Unknown identifier 'a/b'. Between two literals no spaces are needed,6.0/3.0is a division. -
Comparison
==!=<<=>>=, with=accepted for==and<>for!=. -
Logical
&&||!, with the wordsandandoraccepted for&&and||. Unary!binds weaker than a comparison:!a == bmeans!(a == b), anda == !bis a syntax error; writea == (!b). -
Conditional
cond ? a : b, the iif function; it nests to the right,a ? b : c ? d : eisa ? b : (c ? d : e). -
Unary minus applied to an unsigned value gives the signed type of the same width:
-1is an int32, since1is a uint32. -
#before a unit is its number of elements:#Regionis nrofrows(Region). -
a[b]is lookup(b, a)whenbis a relation and value(a, b)whenbis a unit:Region/name[City/Region_rel]gives each city the name of its region,42195[meter]is a length. -
rel -> ais the same lookup written in reading order:City/Region_rel -> namefindsnamein the values unit of the relation, so the container ofnameneed 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.
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.
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/morRoad/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../man 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.
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.
- Expression and Expression syntax
- Literal
- Operator, the precedence table
- Operators and functions
- NameSpace, Using, Parent item
- Indirect expression
GeoDMS ©Object Vision BV. Source code distributed under GNU GPL-3. Documentation distributed under CC BY-SA 4.0.