Programmer Guide/Concepts/Conditional Expressions: Difference between revisions
m (1 revision: Initial import) |
No edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
All commands using conditions (<code>[[User Guide/Workspace/Parameter Processing|IF]]</code>, <code>[[Programmer Guide/Command Reference/DO|DO]]</code>, block-<code>[[User Guide/Workspace/Parameter Processing|IF]]</code>) use the same syntax and evaluation rules. A condition consists of one or more comparisons which are joined with logical (binary) operators. Each comparison compares two values and can evaluate to true or false. | All commands using conditions (<code>[[User Guide/Workspace/Parameter Processing|IF]]</code>, <code>[[Programmer Guide/Command Reference/DO|DO]]</code>, block-<code>[[User Guide/Workspace/Parameter Processing|IF]]</code>) use the same syntax and evaluation rules. A condition consists of one or more comparisons which are joined with logical (binary) operators. Each comparison compares two values and can evaluate to true or false. | ||
Line 14: | Line 12: | ||
:A logical operator, which combines the results of two comparisons. Logical operators are evaluated strictly from left to right; bracketing is not possible. | :A logical operator, which combines the results of two comparisons. Logical operators are evaluated strictly from left to right; bracketing is not possible. | ||
===Logical Operators=== | |||
The logical operators supported by S_TOOLS-STx conditional commands are the following: | The logical operators supported by S_TOOLS-STx conditional commands are the following: | ||
Line 35: | Line 33: | ||
===Comparison Operators=== | |||
S_TOOLS-STx supports two types of comparison operator: | S_TOOLS-STx supports two types of comparison operator: | ||
# Simple comparison operators for numerical expression and case-insensitive string comparisons<code>.</code> | |||
# Pattern matching operators using wild-cards or regular expressions on strings or, more specifically, S_TOOLS-STx names | |||
The general syntax for a comparison is as follows: | The general syntax for a comparison is as follows: | ||
Line 55: | Line 51: | ||
:A comparison operator. | :A comparison operator. | ||
====Simple Comparison==== | |||
The following operators are supported for simple comparisons: | The following operators are supported for simple comparisons: | ||
Line 82: | Line 78: | ||
If the expressions are both numeric, then a numerical comparison is performed. Otherwise, a case<nowiki>-</nowiki>insensitive string comparison is performed. | If the expressions are both numeric, then a numerical comparison is performed. Otherwise, a case<nowiki>-</nowiki>insensitive string comparison is performed. | ||
====Pattern Matching==== | |||
The general syntax of a pattern-matching comparison is: | The general syntax of a pattern-matching comparison is: | ||
Line 158: | Line 154: | ||
===Examples=== | |||
For an example of regular expression in use, see the example script file <code>regular_expressions.sts</code>. | For an example of regular expression in use, see the example script file <code>regular_expressions.sts</code>. |
Revision as of 16:26, 14 March 2011
All commands using conditions (IF
, DO
, block-IF
) use the same syntax and evaluation rules. A condition consists of one or more comparisons which are joined with logical (binary) operators. Each comparison compares two values and can evaluate to true or false.
condition = comparison [loperator comparison loperator .. comparison loperator]
- comparison
- A comparison comprising two expressions separated by a comparison operator. There are two types of comparison supported - see below for comparison operators for details. Both types of comparison can be used within one
IF
command.
- loperator
- A logical operator, which combines the results of two comparisons. Logical operators are evaluated strictly from left to right; bracketing is not possible.
Contents
Logical Operators
The logical operators supported by S_TOOLS-STx conditional commands are the following:
AND | returns true if both comparison results are true |
&& | the same as AND
|
OR | returns true if either of the comparison results are true |
|| | the same as OR
|
Comparison Operators
S_TOOLS-STx supports two types of comparison operator:
- Simple comparison operators for numerical expression and case-insensitive string comparisons
.
- Pattern matching operators using wild-cards or regular expressions on strings or, more specifically, S_TOOLS-STx names
The general syntax for a comparison is as follows:
expression operator expression
- expression
- A numerical expression or a string.
- operator
- A comparison operator.
Simple Comparison
The following operators are supported for simple comparisons:
==
|
evaluates to true if both sides are equal. |
!=
|
evaluates to true if sides are not equal |
<
|
evaluates to true if the left hand side is less than the right hand side |
>
|
evaluates to true if the left hand side is greater than the right hand side |
<=
|
evaluates to true if the left hand side is less than or equal to the right hand side |
>=
|
evaluates to true if the left hand side is greater than or equal to the right hand side |
If the expressions are both numeric, then a numerical comparison is performed. Otherwise, a case-insensitive string comparison is performed.
Pattern Matching
The general syntax of a pattern-matching comparison is:
string operator mask
E.g.:
'the quick brown fox' !SI '*brown*' // search for the word 'brown' in the left hand side string
The string can also be a 'name' - subject to the syntax restrictions for S_TOOLS-STx names. There are two types of pattern matching supported by S_TOOLS-STx conditional commands.
Wild-card pattern matching:
=SI
|
return true if string matches pattern, ignoring the case |
!SI
|
return true if string does not match pattern, ignoring the case |
=SR
|
return true if the string matches the pattern, respecting the case |
!SR
|
return true if the string does not match the pattern, respecting the case |
=NI
|
return true if name matches pattern, ignoring the case |
!NI
|
return true if name does not match pattern, ignoring the case |
=NR
|
return true if the name matches the pattern, respecting the case |
!NR
|
return true if the name does not match the pattern, respecting the case |
POSIX regular expression pattern matching:
=RSI
|
returns true if the string matches the regular expression, ignoring case |
!RSI
|
return true if string does not match the regular expression, ignoring the case |
=RSR
|
returns true if the string matches the regular expression, respecting case |
!RSR
|
return true if the string does not match the regular expression, respecting the case |
=RNI
|
returns true if the name matches the regular expression, ignoring case |
!RNI
|
return true if name does not match the regular expression, ignoring the case |
=RNR
|
returns true if the string matches the regular expression, respecting case |
!RNR
|
return true if the name does not match the regular expression, respecting the case |
Regular expressions make heavy use of characters that have a special meaning for S_TOOLS-STx. In order to use such characters, you need to escape them with the S_TOOLS-STx escape character, "`
" (back-tick). The S_TOOLS-STx regular expressions are implemented using the TRE library.
Examples
For an example of regular expression in use, see the example script file regular_expressions.sts
.