2 Syntax
Whitespace can be a space character, a tab character, a newline character, or a comment. Implementations can define additional whitespace characters.
A comment can be single-line or delimited. Although comments count as whitespace, the beginning of a comment can blend with a preceding token, so in general comments should be surrounded by genuine whitespace.
A single-line comment consists of two slash characters in a row, followed by any number of characters up to and including the first newline character or the end of the source record. For example, // This line is a kludge!
.
A delimited comment consists of a slash character immediately followed by a star character, any number of characters including balanced slash-star / star-slash pairs, and finally a star character immediately followed by a slash character. For example, /* set x to 3 */
.
A single-line comment may appear within a delimited comment; occurances of slash-star or star-slash within the single line comment are ignored.
A token is a name, a #-word, an operator, a number, a character literal, a string literal, a symbol literal, or punctuation.
A name is one of the following four possibilities:
An alphabetic character is any of the 26 letters of the Roman alphabet in upper and lower case.
A numeric character is any of the 10 digits.
A graphic character is one of the following:
!
&
*
<
=
>
|
^
$
%
@
_
A name character is an alphabetic character, a numeric character, a graphic character, or one of the following:
-
+
~
?
/
The rich set of name characters means that name and operator tokens can blend. Thus Dylan programs usually set off operators with whitespace.
Implementations can add additional characters but programs using them will not be portable.
A #-word is one of #t
, #f
, #next
, #rest
, #key
, or #all-keys
. The first two are literal constants, the others are used in parameter lists. Implementations can add additional implementation-defined #-words, but programmers cannot add their own #-words.
An operator is one of the following:
+
addition
-
subtraction and negation
*
multiplication
/
division
^
exponentiation
=
equality
==
identity
<
less than
>
greater than
<=
less than or equal
>=
greater than or equal
~=
not equal
~==
not identical
&
logical and
|
logical or
:=
assignment
~
logical negation
Programmers cannot add their own operators.
A number is a decimal integer with an optional leading sign, a binary integer, an octal integer, a hexadecimal integer, a ratio of two decimal integers with an optional leading sign, or a floating-point number. The complete syntax of numbers is given in "Numbers" on page 404.
A character literal is a printing character (including space, but not ' nor \) or a backslash escape sequence enclosed in a pair of single-quote characters '.
A string literal is a sequence of printing characters (including space, but not " nor \) and backslash escape sequences enclosed in a pair of double-quote characters ".
The backslash escape sequences used in character and string literals allow "quoting" of the special characters ', ", and \, provide names for "control" characters such as newline, and allow Unicode characters to be specified by their hexadecimal codes.
A symbol literal is a keyword or a unique string. A keyword is a name followed immediately by a colon character ":". A unique string is a sharp sign "#" followed immediately by a string literal.
Punctuation is one of the following:
(
)
parentheses
[
]
square brackets
{
, }
curly brackets
,
comma
.
period
;
semicolon
=
defaulting/initialization
::
type specialization
==
singleton specialization
=>
arrow
#(
list/pair literal
#[
vector literal
?
, ??
macro pattern variables
...
macro ellipsis
Note that some tokens are both punctuation and operators. This ambiguity is resolved by grammatical context.
Note that some punctuation tokens (for example period and equal sign) are capable of blending into some other tokens. Where this can occur, whitespace must be inserted to delimit the token boundary.
Generated with Harlequin WebMaker