45 of 172
ZBasic Language Reference 38 ZX Microcontroller Family 2.6.3 Numeric Literals - Real Values A real numeric literal consists of one or more decimal digits, optionally with a leading plus or minus sign, followed by either a decimal point and one or more decimal digits or the letter E followed by one or more decimal digits also optionally prefixed by a plus or minus sign. If the fractional part is present, it may also be followed by an exponent specification. For compatibility with other Basic dialects, a literal that would otherwise be an integral literal will be interpreted as a real literal if it is immediately followed by an exclamation mark. Real literals have the type Single. Examples of real literals: 3.14159 +6.02e23 3e10 -300! BasicX Compatibility Note In BasicX compatibility mode, real literals must either contain a decimal point or have a type designation suffix ! or # to force them to be recognized as type Single. A literal like 12e2 represents the integer value 1200. 2.6.4 String Literals A string literal consists of zero or more characters enclosed in quotation marks. Note that a string may not be continued on the next line by ending the first line with an underscore. However, you may use the concatenation operator in conjunction with the underscore continuation to span line boundaries. The compiler will combine the operands to the concatenation operator as long as they are both string constants. String literals have the type String. Examples of String Literals: "" "Hello, world!" "The quick brown fox" & _ " jumped over the lazy dog." "Hello, ""Joe""!" The third and fourth lines above show how to use the concatenation operator and line continuation to construct longer strings. Note that the underscore must be the last character on the line and that there must be a space or tab character preceding it. The last example shows how to include a quotation mark within a string literal. Two consecutive quote marks are reduced to one in the actual string. If you want two adjacent quote marks in the string, you’ll have to double each of them. 2.6.5 Built-in Binary Constants Although they are technically not numeric literals, ZBasic provides some built-in Byte constants that serve the same purpose. The constants begin with the letters BX and are followed by exactly 8 binary digits (0-1). There may be an underscore between any pair of binary digits to enhance readability. These constants are of type Byte and may only be used where a Byte type is allowed. These built-in constants are supported for compatibility with BasicX. It is recommended that new applications use binary literals (described in Section 2.6.2) since they are more generally useful. Examples Bx0100_1101 BX01_00_11_01