next up previous contents
Next: Field calculator Up: Field evaluator Previous: Field evaluator

Expressions

 

The NDA kernel has a simple parser which can be used to evaluate an expression. How does it work? Basically, the parser provides three services: parsing given expressions, checking data types, and evaluating an expression.

The parser is a syntax involving the following operators and operands:

tabular1124

The type checking is performed after an expression has been parsed to an abstract syntax tree. Then, the types of the operands for each operator are checked. In addition, the lengths of the data fields are checked. When the data fields are referred from an expression, they must have necessarily the same length or the length 1, so that the evaluation is valid. Namely, the expression is evaluated record by record (index by index). Data fields with the length 1 are interpreted as scalar variables, and their values are always read by the index 0.

The evaluation of the expression depends on the operation which uses the parser. If the parser is used to compute a new field (the command expr), then the returned value of the evaluation can be of any type. Instead, when the parser is used to evaluate the truth-value of the expression, the parsing should produce boolean values. Then, the highest operators must be the comparing and logical operators.

Example (ex4.2): The following commands use the expression evaluation (see Sections 4.2.2, 4.2.3, 4.2.4 and 7.3.6).

...
# compute new fields
NDA> expr -dout boston -fout znPrice
     -expr 'boston.zn'/'boston.rate'; -v
...
# select indexes to a new class according to a given rule
NDA> selcl -cout c1/cld -clout bigZn 
     -expr ('boston.zn'>3.0) AND ('boston.rate'<25); -v
...
# select a new data (values under the average)
# now 'rate.avg' is a variable for a scalar
NDA> select avgfld -f boston.rate
NDA> fldstat -d avgfld -dout rate -avg
NDA> selrec -d boston -dout data
     -expr ('boston.rate'< 'rate.avg'); -v
...
# set neurons to be visible by a given rule
NDA> nvsbl grp1 -expr 'sta.hits'> 0; -v



Erkki Hakkinen
Thu Sep 24 11:51:34 EET DST 1998