13 of 158
7 Chapter 2 - ZBasic Language Elements The logic of a program is described in the ZBasic language using identifiers, keywords, literal values, expression operators, statements, etc. These elements are all more fully described in this chapter. 2.1 Identifiers In ZBasic, as in most computer languages, all constants, variables, subroutines and functions have a name. Such names are generally referred to as identifiers and each computer language has rules that specify how an identifier may be formed. In ZBasic an identifier must begin with an alphabetic character (A-Z, a-z) and may contain zero or more additional characters which may be alphabetic, numeric (0-9) or an underscore. There is virtually no maximum number of characters that an identifier may contain (in reality it is limited by the amount of memory available on your computer) but as a practical matter identifiers seldom exceed 15 to 20 characters. Beyond that they become somewhat cumbersome to type. As mentioned previously, the alphabetic case of the letters of an identifier is insignificant. The variable myVar is the considered the same as the variable MyVar. There is a set of identifiers that are reserved for special purposes and cannot be otherwise used in your program. Some of the reserved words are data type names, some are used as keywords in ZBasic statements (If, For, Sub, etc.). Some reserved identifiers have no current use in ZBasic but they are reserved nonetheless because they are keywords in other Basic dialects and may be incorporated into ZBasic in the future. If you attempt to use a reserved word in a role other than its predetermined role the compiler will issue an error message pointing out the unacceptable use. See Appendix A for a complete list of reserved words. 2.2 Data Types The table below describes the fundamental data types available in ZBasic. There are a few additional data types that are used for special purposes that will be described later. Fundamental Data Types Data Type Name Range of Values Boolean True, False Byte 0 to 255 Integer -32,768 to 32,767 UnsignedInteger 0 to 65,535 Long -2,147,483,648 to 2,147,483,647 UnsignedLong 0 to 4,294,967,295 Single approximately ±1.4e-45 to ±3.4e+38 and 0.0 String 0 to 255 characters It is important to note that some mathematical operations on floating point values (type Single) result in certain special values that indicate an exceptional result. Among these special values are ones that represent positive infinity, negative infinity and a general category referred to as “not a number”, called NaN. The System Library function SngClass() returns a value indicating the class to which a floating point value belongs. See the ZBasic System Library Reference Manual for more information on the SngClass() function. In addition to the fundamental data types enumerated in the table above, ZBasic supports several additional special-purpose types. There are two additional integral-value types that are collectively referred to as sub-byte types – Bit and Nibble. These are useful for reducing the amount of space used for small-valued data but they are not quite as efficient with respect to code size as using Byte types. See Section 3.22 for more information on these special types. Also, two special string types are available – Bounded Strings and Fixed Length strings. These are supported largely for compatibility with BasicX but may be useful in special situations. See Section 2.11.1 and Section 2.11.2 for more information on Bounded Strings and Fixed Length strings, respectively.