Prev: Comments
Literals
Literals are concrete values specified explicitly in the code. Except for array literals, they are fixed and cannot change during script execution. Array literals are more complex and discussed in section * ().
| | |
SimpleLiteral := NumberLiteral | StringLiteral | BooleanLiteral |
FunctionLiteral | NullLiteral .
|
|
Number Literals
A number literal is a sequence of digits, with an optional decimal point, and an optional decimal exponent. The digits must not be separated by white space or thousands separators:
print 0
→ 0
print 3.1415927
→ 3.1415927
print 6.02214199e+23
→ 6.022142E+23
print 1E-3
→ 0.001
|
Integer numbers can also be written in hexadecimal notation, by prefixing them with 0x:
print 0xff
→ 255
print 0x1000
→ 4096
|
| | |
NumberLiteral :=
Digit {Digit} ['.' {Digit}]
[(E' | 'e') ['-' | '+'] Digit {Digit}] |
'0x' HexDigit {HexDigit} .
Digit :=
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' .
HexDigit := Digit | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' |
'a' | 'b' | 'c' | 'd' | 'e' | 'f' .
|
|
String Literals
A string literal is a sequence of characters between single or double quotes.
print 'Hello, world!'
→ Hello, world!
print "That's nice"
→ That's nice
|
In order to produce all characters, the backslash \ serves as escape for the following character. For instance, if the quote used to delimit the string literal occurs inside the string, it must be escaped. Likewise, the backslash itself must be escaped, as is often seen in path names:
print "A quote: \"To be, or not to be...\""
→ A quote: "To be, or not to be..."
print 'That\'s nice'
→ That's nice
print "c:\\system\\apps"
→ c:\system\apps
|
There are a few characters which have a special meaning when escaped:
| \f | form feed (ASCII 12) |
| \n | new line or line feed (ASCII 10) |
| \r | carriage return (ASCII 13) |
| \t | horizontal tab (ASCII 9) |
| \u | hexadecimal UNICODE® (UTF-16) follows |
| |
print "Line1\nLine2"
→ Line1
Line2
print "Item1\tItem2"
→ Item1 Item2
print "g\u00e9nial"
→ génial
|
The maximum length of a string literal is 256 characters.
| | |
StringLiteral := '"' {Char | EscapeChar | "'"} '"' |
"'" {Char | EscapeChar | '"'} "'" .
Char := (printable ISO-8859-1 char except ', ", \)
EscapeChar := '\' ('n' | 'r' | 't' |
'u' HexDigit HexDigit HexDigit HexDigit | (printable char)) .
|
|
Boolean Literals
Not surprisingly, there are just two boolean literals: true and false.
| | |
BooleanLiteral := false | true .
|
|
Function Literals
A function literal is a reference to a (already declared) function. Section * () explains function references.
| | |
FunctionLiteral := '&' [ModulePrefix] Identifier .
|
|
Null Literal
The null literal denotes a "special" value which is different from all other values.
Next: Variables© 2004-2011 airbit AG, CH-8008 Zürich
Document AB-M-REF-887