MPD has five basic types: bool, int, real, char, string representing booleans, integers, real numbers, characters and strings.
The boolean operators produce booleans as result. Boolean operators are lazy. For example if the first operand of and and evaluates to false then the second operand is never evaluated.
Integers are seqences decimal digits, octal numbers, or hexadecimal numbers. Examples of integers are
11 4096 1333Q abcdefX
A real literal has the general form
integer_part . fraction_part exponent_part |
The three parts and the decimal point are optional, subject to certain restrictions. Examples of reals are
11.2 3.1415927 0.0 0. .0 1.23e-45 1.23E-45 .123e-44 421e+3 421e3 |
Character literals are single ASCII characters enclosed in single quotes or one of the special characters.
\n |
newline | \a |
alert |
\t |
tab | \e |
escape |
\b |
backspace | \v |
vertical tab |
\r |
return | \f |
form feed |
\' |
single quote | \`` |
double quote |
\\ |
backslash | ||
\ooo |
bit pattern of octal digits | ||
\xhh |
bit pattern of hexadecimal digits | ||
\c |
character c |
Examples of characters are
'a' 'Z' '4' '\'' '\e' & '\33' '\x1b' |
Strings are sequences of zero or more ASCII characters enclosed in double quotes. When string variables are declared the string is given a maximum length
string[maxlen] |
Examples of strings are
"" "alpha" "Z" "44" "I'm having fun" "here is a in the middle" |
There is only one binary string operator used to concatenate strings, ||. The predefined function length and maxlength return the length of a string and maximum length of a string resp.
All basic types are ordered. Booleans, characters, integers and reals are ordered according to their natural ordering. Strings are ordered lexicographically. Enumerations are the only user defined ordered type.
Relational operators compare their operands and return a boolean value that reflects the result of the comparison. The relational operators include the usual comparisons:
= != < > <= >= |
The precedence of relational is above that of the boolean operators. Thus you may write either of
a < b and c > d (a < b) and (c > d) |
The relational operators are also defined for the ordered user defined types and the equality operators are also defined for pointers and capabilities.
|