Zbex variable declaration statements
Previous chapter Utility programs |
Zbex Manual |
Next Chapter Assignment statements |
The Zbex language recognizes four data types: strings, bit-strings, integer numbers, and real numbers. Each of these data types can have two forms: literal (fixed for the life of the program) and variable. Literal data types need no introduction; the compiler accepts them wherever they are found. Variable data types must be declared before they can appear in a program.
Strings
A string is a sequence of bytes of specified length. The length is a integral part of the data type. Literal strings are enclosed in double quotes. Examples:
"Now is the time.", "123435.6789"
Note that the contents of a string is case sensitive. Variable strings are declared using the str statement, following by a list of variables (separated by commas). Each variable name must be followed immediately by a dot and a number. The number tells the compiler how many bytes of computer memory to allocate for the string variable. Example:
str temp.100, file.100, big.10000000
This statement identifies three string variables to the compiler: (1) temp, with maximum length of 100 bytes, (2) file, with maximum length of 100 bytes, and (3) big, with maximum length of ten million bytes.
At the onset of a program, all string variables are assigned a run-time length of zero. We call this the null string. When a string takes on a value other than the null string, this value has two components, a length, and a sequence of bytes. Example:
temp = "Now is the time "
In this statement, the string variable, temp, is assigned a length of 17 and the byte sequence Now is the time.
Bit strings
A bit string is a sequence of bits of specified length. The length is a integral part of the data type. Literal strings are represented as a stream of zeros and ones enclosed in double quotes. Examples:
"010011", "0000000101010101", "00000000000"
Variable bit strings are declared using the bstr statement, following by a list of variables (separated by commas). Each variable name must be followed immediately by a dot and a number. The number tells the compiler how many bits of computer memory to allocate for the bit string variable. Example:
bstr test1.100, test2.100, bigbit.5000000
This statement identifies three bit string variables. (1) test1, with maximum length of 100 bits, (2) test2, with maximum length of 100 bits, and (3) bigbit, with maximum length of five million bits.
At the onset of a program, all bit string variables are assigned a run-time length of zero. We call this the null bit string. When a bit string takes on a value other than the null bit string, this value has two components, a length, and a sequence of bits. Example:
test1 = "10101010101"
In this statement, the bit string variable, test1, is assigned a length of 11 and the bit sequence 10101010101.
Integer numbers
An integer number can have any value from -2,147,483,648 to +2,147,483,647. Literal integers can be represented either in decimal format or in hexadecimal format. Examples:
0 10 010 +20 -50 0xff 0x00ff 0x7fffffff
The second and third examples are equivalent. The plus sign in the fourth example is optional. The minus sign in the fifth example is not optional, and it must come immediately before the number. The sixth and seventh examples are equivalent and have the decimal value of 255. The eighth example is the largest positive value that can be taken by an integer number.
Variable integers are declared using the int statement, following by a list of variables (separated by commas). Example:
int a,b,d,e,f
This statement identifies six integer variables to the compiler: a, b, c, d, e and f.
At the onset of a program, all integer variables are automatically assigned a run-time value of zero.
Real numbers
A real number can have up to sixteen significant digits and take on absolute (plus or minus) values from 1.0 * 10(exponent -309) to 9.9 * 10 (exponent 308) as well as the value 0. Literal real numbers can be represented either in fixed point format or floating point format. Examples:
0.0 1.0 1.000 +2.34e+20 -3.54e-30
The second and third examples are equivalent. The plus signs in the fourth example are optional. The minus signs in the fifth example is not optional, and they must come immediately before the numbers thay modify.
Variable real numbers are declared using the real statement, following by a list of variables (separated by commas). Example:
real x,y,z
This statement identifies three real variables to the compiler: x, y and z.
At the onset of a program, all real variables are automatically assigned a run-time value of zero.
Previous chapter Utility programs |
Zbex Manual |
Next Chapter Assignment statements |