Lexical Format¶
Characters¶
The text format assigns meaning to source text, which consists of a sequence of characters. Characters are assumed to be represented as valid Unicode (Section 2.4) scalar values.
Tokens¶
The character stream in the source text is divided, from left to right, into a sequence of tokens, as defined by the following grammar.
Tokens are formed from the input character stream according to the longest match rule. That is, the next token always consists of the longest possible sequence of characters that is recognized by the above lexical grammar. Tokens can be separated by white space, but except for strings, they cannot themselves contain whitespace.
The set of keyword tokens is defined implicitly, by all occurrences of a terminal symbol in literal form, such as \(\def\mathdef2007#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2007{keyword}\), in a syntactic production of this chapter.
Any token that does not fall into any of the other categories is considered reserved, and cannot occur in source text.
Note
The effect of defining the set of reserved tokens is that all tokens must be separated by either parentheses or white space. For example, \(\def\mathdef2008#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2008{0\$x}\) is a single reserved token. Consequently, it is not recognized as two separate tokens \(\def\mathdef2009#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2009{0}\) and \(\def\mathdef2010#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef2010{\$x}\), but instead disallowed. This property of tokenization is not affected by the fact that the definition of reserved tokens overlaps with other token classes.
White Space¶
White space is any sequence of literal space characters, formatting characters, or comments. The allowed formatting characters correspond to a subset of the ASCII format effectors, namely, horizontal tabulation (\(\def\mathdef2011#1{\mathrm{U{+}#1}}\mathdef2011{09}\)), line feed (\(\def\mathdef2012#1{\mathrm{U{+}#1}}\mathdef2012{0A}\)), and carriage return (\(\def\mathdef2013#1{\mathrm{U{+}#1}}\mathdef2013{0D}\)).
The only relevance of white space is to separate tokens. It is otherwise ignored.
Comments¶
A comment can either be a line comment, started with a double semicolon \(\def\mathdef1982#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef1982{{;}{;}}\) and extending to the end of the line, or a block comment, enclosed in delimiters \(\def\mathdef1980#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef1980{{(}{;}} \dots \def\mathdef1981#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef1981{{;}{)}}\). Block comments can be nested.
Here, the pseudo token \(\mathtt{eof}\) indicates the end of the input. The look-ahead restrictions on the productions for \(\href{../text/lexical.html#text-comment}{\mathtt{blockchar}}\) disambiguate the grammar such that only well-bracketed uses of block comment delimiters are allowed.
Note
Any formatting and control characters are allowed inside comments.