Building Expressions. DORIC 9.65, INFO-Text software
Advertentie
Advertentie
Building Expressions
Arithmetic
expressions
You use arithmetic expressions in INFO commands to represent values that cannot be known until some set of data is actually processed. You can also use arithmetic expressions to perform calculations using known data. An arithmetic expression represents a particular value only when INFO is executing the command in which it is found.
Arithmetic expressions can contain up to 30 operands, limited by INFO's 200-character maximum command width, separated from one another by arithmetic operators. To override the default precedence of the operators, or for ease of understanding, an arithmetic expression can contain parentheses.
Each element within the arithmetic expression must be surrounded by blanks. This applies equally to the operands, operators, and parentheses.
An arithmetic expression takes the following form:
[operand-1] operator operand-2
Each operand is one of the following types of data, all of which can be used together in the same expression: n
A numeric- or data-type item name n
A system item or system variable n
A numeric or character literal
An operator is a 1 or 2 character reserved word that defines the arithmetic operation performed using the operand(s). Each operator has a precedence level which determines in what order the operator is applied as INFO evaluates the expression.
When evaluating an arithmetic expression, INFO applies operators with higher precedence before those with lower precedence. Table BE-1 below lists some arithmetic operators and their precedence level: see Appendix L
Functions for the complete list. When INFO evaluates an arithmetic expression, it processes as follows:
INFO Reference Manual Introduction xix
Building Expressions
_
**
Table BE-1
Operator
LN
WD n
Following the order of precedence shown below for each of the operators, INFO performs the computations defined by the operands having higher precedence before those defined by the operands having lower precedence.
n
When more than one instance of a precedence level is present, INFO moves from left to right through the expression to process the multiple instances.
n
When it encounters parentheses, INFO performs the computations within parentheses, following rules 1 and 2 above, before evaluating the expressions outside of the parentheses.
1
1
1
2
Precedence level* Description
Natural logarithm. Use with right hand side operand only. Calculates the natural logarithm of the operand.
The operand must be defined as numeric and must be positive.
Width computation. Use with right hand side operand only. Calculates the width of the operand, excluding trawiling (padded) blanks. The operand must be defined as character (Type C).
Unary minus. Negates the following operand.
Exponentiation. Left operand is calculated to the power of the right operand. Because exponentiation is performed using logarithms, the left operand must be positive..
xx Introduction INFO Reference Manual
Building Expressions
Table BE-1 (cont’d)
-
/
Operator
** 0.5
*
+
2
3
3
4
4
Precedence level* Description
Square root. See exponentiation for description.
Multiplication. Left and right operands are multiplied. Equal in precedence to division.
Division. Left operand is divided by thevalue of the right operand. Equal in precedence to multiplication.
Addition. Left and right operands are added together. Equal in precedence to subtraction.
Subtraction. Right operand is subtracted from left operand. Equal in precedence to addition.
*1 is the highest level of precedence; 4 is the lowest.
INFO Reference Manual Introduction xxi
Building Expressions
Operator
EQ (=)
NE (<>)
GE
LE
GT (>)
LT (<)
CN
NC
BW
NB
Logical expressions
Logical expressions specify a relation between values that is tested for truth or falsity. Logical expressions can only
evaluate to "true" or "false." You use logical expressions in
INFO commands to represent criteria for performing certain operations.
General
INFO evaluates all logical expressions from left to right.
considerations You can use parentheses to override this default order of evaluation.
Simple logical expressions
The length of any logical expression is limited only by
INFO's 200-character command buffer.
Logical expressions can be simple or compound. A simple logical expression takes the form:
operand-1 operator operand-2
where each operand is an item name, a system item or system variable, or a numeric, character, or date literal.
Each operator is a 2-character reserved word that specifies the logical relation tested using the two operands. A few logical operators have alternative forms: algebraic symbols (in parentheses following each operator reserved word in the following table) that are interchangeable with their 2-character forms.
Meaning
Operand-1 equal to operand-2
Operand-1 not equal to operand-2
Operand-1 greater than or equal to operand-2
Operand-1 less than or equal to operand-2
Operand-1 greater than operand-2
Operand-1 less than operand-2
Operand-1 contains the value of operand-2
Operand-1 does not contain the value of operand-2
Operand-1 begins with operand-2
Operand-1 does not begin with operand-2 xxii Introduction INFO Reference Manual
Building Expressions
Compound logical expressions
Each operator in a logical expression must have a blank space on either side of it. You can specify any type of data item on either side of a logical operator, just so the operands are of a compatible data type (for example, you cannot compare a numeric item with a literal string).
If you attempt to compare character data with numeric data in a logical expression, INFO accepts the expression syntactically, but the result of such a comparison is almost always incorrect.
You build compound logical expressions using simple ones joined by logical connectors. Any number of simple logical expressions can be joined to form one compound logical expression.
Logical connectors are themselves logical operators. As
INFO evaluates a compound logical expression, a logical connector performs a standard Boolean logical operation using the truth values from the (simple or compound) logical expressions that you specify to its left and right.
A compound logical expression takes the form:
logical-expression connector logical-expression
where logical-expression is a valid simple or compound
INFO logical expression, and connector is one of the
INFO reserved words AND, OR, or XOR.
To evaluate a logical expression as true: n
The connector AND requires that all logical expressions be true.
n
The connector OR requires thatat least one of the logical expressions be true.
n
The connector XOR (exclusive OR) requires that one and only one of the logical expressions be true.
INFO Reference Manual Introduction xxiii
Building Expressions
Word
Expressions
Word expressions specify character strings that are searched for in the concordable items of the selected
(INFO-Text only)
extended datafile. Word expressions represent string literals, words, or phrases that INFO attempts to locate in the specified concordable items when you reselect extended datafile records, or list or print extended datafile records.
Word expressions must conform to the following syntax: word [W [.]#-of-words word [@DF-item-1[,DF-item-2[...]]]] string
*synonym-list
[words-before,words-after
[SENTENCE synonym-member* [PARAGRAPH string
*synonym-list synonym-member* match-word match-word
word can include any characters except blanks, the current DELIMITER character, punctuation characters, and the special characters \ (backslash) and % (percent sign).
string represents any string literal enclosed in single quotes.
synonym-list represents the name of a synonym list.
synonym-member represents the name of a member of a synonym list.
match-word represents a combination of characters valid for a word and including the special characters
\(backslash) or % (percent sign). The backslash, also called the truncation character, indicates any prefix, suffix, or infix string in a word, as illustrated in the following
examples
ALPHA\
\ALPHA
Matches all words that begin with the string 'ALPHA'.
Matches all words that end with the string
'ALPHA'.
xxiv Introduction INFO Reference Manual
Building Expressions
\ALPHA\ Matches all words that contain the string 'ALPHA'.
ALP\\A Matches all words that begin with the string 'ALP' and end with the string 'A'.
The percent sign represents a character position in a word which can take any value, as illustrated below:
%%A
A%%%%
Matches any 3-character word that ends with the character 'A'.
Matches any 5-character word that begins with the character 'A'.
You can combine the backslash and percent sign in the same match word.
A list of alternate prefix, suffix, or infix strings enclosed in square brackets ([ and ]) can also represent the literal string or character portion of a match word. For example:
[A,B,D]!
[A,B]%%%%
Matches any word that begins with the characters 'A', 'B', or 'D'.
Matches any 5-character word that begins with the characters 'A' or 'B'.
W means "within" and is required for word expressions that have a textual context for the specified word term.
#-of-words directs INFO to search for a word that matches the word term preceding WITHIN and appears within the specified number of words of the word-term that follows.
For example, 'APPLES W 2 PEARS' requests INFO to find occurrences of the word 'APPLES' that appear within 2 words of the word 'PEARS'. When #-of-words immediately follows a period, INFO searches for occurrences of the word that match the preceding word term and that appear exactly within the specified number of words
For example, 'APPLES W .2 PEARS' tells INFO to find occurrences of the word 'APPLES' that occur exactly 2 words away from the word 'PEARS'.
INFO Reference Manual Introduction xxv
Building Expressions connectors in word expressions
words-before,words-after directs INFO to search for a word that matches the preceding word term and appears either the specified number of words before or the specified number of words after the word term that follows. For example, 'APPLES W 2,3 PEARS' tells INFO to find occurrences of the word 'APPLES' that appear within 2 words before or within 3 words after the word 'PEARS'.
SENTENCE directs INFO to search for a word that matches the preceding word term and that appears in the same sentence as the word term that follows. For example,
'APPLES W S PEARS' requests INFO to find occurrences of the word 'APPLES' that appear in the same sentence as the word 'PEARS'.
PARAGRAPH directs INFO to search for occurrences of a word that match the preceding word term and that appear within the same paragraph as the word term that follows.
For example, 'APPLES W P PEARS' tells INFO to find occurrences of the word 'APPLES' that appear in the same paragraph as the word 'PEARS'.
@ directs INFO to limit its search to only the item or items specified. You can specify a list of any subset of the A-, or concordable C-type items in the selected extended datafile, limited only by the 200-character length of the
INFO command buffer. If you do not include the @ option,
INFO searches all concordable items in the selected extended data file for occurrences of text that match the specified word term.
You can form compound word expressions by using the INFO logical connector keywords AND, OR, and XOR (described above in the Logical
Expressions section). You can use these words in word expressions only if you specify them as surrounded by single quotes and if they are not found in the applicable extended datafile's stopword file.
xxvi Introduction INFO Reference Manual
Downloaden
Advertentie