Zbex relations

From CCARH Wiki
Jump to navigation Jump to search
Previous chapter
Program control
Zbex
Manual
Next Chapter
Functions


A relation is used to describe a test condition. Examples of relations are: x < y, x = y, and x > y. The condition described by a relation is either true or false, depending on the values of the variables at run time.

A relation has the following structure:

     <entity> <relational operator> <entity> 

The <entity> may be a variable, a literal, a non-string function, a non-string expression, or (right hand side) a set of characters (numbers between 0 and 255). The entities on each side of a relation must be of the same variable type.


Strings

For strings there are eight relational operators:

The first six operators evaluate the two strings of a relation, byte by byte, treating each byte arithmetically. If a difference is found, a definitive result can be given for operators two through six. Only if all bytes are found to be the same, and the lengths also the same, are the strings determined to be equal. If the lengths are unequal, but the strings are identical up to the length of the shorter string, the longer string is determined to be greater than the shorter string.

The "in" operator requires that the right hand side be a set. The left hand side must be a string or a substring. The relation is evaluated as true if and only if all characters in the string or substring are members of the set. If the left hand side is a single character string (string with length one), the relation is true if that character is a member of the set.

The "con" operator may have a string, a substring, or set on the right hand side. The left hand side may be a string or a substring. If the right hand side is a string or substring, the relation is true if the left hand string is equal to or contains the string or substring on the right. If the right hand side is a set, the relation is true if any byte in the left hand entity is in the set.

The con operator has one other property. Zbex has five special integer variables, trp, sze, rem, mpt, and sub, which are set by various runtime operations. Two of them, mpt (match point) and sub (subscript), are given new values when the "con" relation is true. The value assigned to mpt is the position in the left hand string or substring where the truthful result was first detected. The value assinged to sub is the subscript in the left hand string variable where the truthful result was first detected. The difference between "position" (value of mpt) and "subscript" (value of sub) is illustrated by the following example:

         str test.5 
   
         test = "abcde" 
         if test{3..5} con "e" 
           putc mpt = ~mpt   sub = ~sub 
         end 

In this example, the "con" relation is true and mpt is set to 3, the point in the sub-string "cde" where the "e" was found. sub is set to 5, which is the subscript in the variable test "abcde" where the "e" occurs.


In this section, reference was made to an entity called a set.. A set is sub-set of the numbers 0 through 255, i.e., the possible values of a byte. For this reason, we also refer to a set as a character set. Below are some examples of sets.


        1.  ['a'..'z']                 the small alphabet 
        2.  ['A'..'Z','a'..'z']        the large and small alphabet 
        3.  ['0'..'9']                 the digits 
        4.  [48..57]                   the values 48 to 57, which 
                                       are the ASCII values for 
                                       the numbers 0 to 9.  Sets 
                                       3. and 4. are the same.  
        5.  [32]                       the value 32.   
        6.  [' ']                      the space character, ASCII 32.  
                                       Sets 5. and 6. are the same.  
        7.  ['A'..'z']                 all values between 'A' = 65 
                                       and 'z' = 122.  

If you don't know or can't remember the ASCII values for the various characters, don't worry about it. Few people have reason to remember these values. When I want to be reminded of the ASCII values for various characters, I just write and run the following program:

          str a.1 
          int i 
          loop 
            getc a 
            i = ors(a) 
            putc ~a  = ASCII ~i 
          repeat 
          run 

The expression ors(a) is a function which converts the string a to an integer. We will discuss functions in the next section.


Bit strings, Integers, Real numbers

For the non-string data types there are six relational operators.

For bit strings, these operators behave in the same manner as with strings. For the numerical data types, these operators behave in the usual manner. The operators are sign sensitive, i.e., a negative number closer to zero is larger than a negative number farther from zero.



Previous chapter
Program control
Zbex
Manual
Next Chapter
Functions