Zbex assignment statements

From CCARH Wiki
Revision as of 14:57, 13 October 2010 by Craig (talk | contribs) (created page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The most common way to set the value of a variable is with an assignment statement. Assignment statements take the form <variable> = <expression>. The two sides of an assignment statement must have data types of the same type. The expression on the right may have one or more elements. For strings and bit strings, elements in an expression are combined using the concatenate operator ( // ). For integers and real numbers, elements are combined using one or more of the arithmetic operators:

integer and real integer only
+ = add
- = substract
* = multiply
/ = divide
& = and
| = or
>> = shift right
<< = shift left


In the absense of parentheses, arithmetic operators are processed in a left to right fashion, i.e., not according to the rules of algebra.

An element of an expression may be a literal, a variable or a function. Functions will be covered later. Examples:

Strings

        str temp.80,name.80 
         
        name = "<your name>" 
        temp = "Good afternoon, " // name // ", I am pleased " 
        temp = temp // "to meet you." 

In this case, the string temp has the value

        Good afternoon, <your name>, I am pleased to meet you.  

Note that the concatenate operator ( // ) must have a blank on either side of it.

Bit strings

        bstr test1.80, test2.80 

        test1 = "1010101" 
        test2 = test1 // "000" // test1 

In this case, the bit string test2 has the value 10101010001010101.

Intergers

        int  a,b,c 
   
        a = 10 
        b = 20 
        c = a >> 2 * b + 4 

In this case, the value of c is 10 shifted right 2 = 2, times 20 = 40 plus 4 = 44.

Real numbers

        real  x,y,z 
    
        x = 10.0 
        y = 5.0 
        z = x - 3.0 / y * 3.0 

In this case, the value of z is 10.0 minus 3.0 = 7.0, divided by 5.0 = 1.40, time 3.0 = 4.2

For interger and real number operations, you can use parentheses to control the order in which operations are performed.

For all assignment statements the right-hand side is evaluated before the left-hand side is changed. Examples:

     bstr test1.80 
       
     test1 = "1010101" 
     test1 = test1 // "000" // test1 

In this case, the bit string test1 has the value 10101010001010101.

     int  a 
     
     a = 10 
     a = a + 1 

In this case, the value of a is 11.