Tokenization

HC Overview Tokenization
Commandline option -run Debugging

Tokenization

Names of procedures, variables, and property lists are case-insensitive. So are the special words END, TRUE, and FALSE. Case of letters is preserved in everything you type, however.

Within square brackets, words are delimited only by spaces and square brackets.
	[2+3]
is a list containing one word. Note, however, that the Logo primitives that interpret such a list as a Logo instruction or expression (run, if, etc.) reparse the list as if it had not been typed inside brackets.

After a quotation mark outside square brackets, a word is delimited by a space, a square bracket, or a parenthesis.

A word not after a quotation mark or inside square brackets is delimited by a
	space, a bracket, a parenthesis,
	or an infix operator + - * / ^ = < > += -= *= /= == != <= >=.
Note that words following colons are in this category. Note that quote and colon are not delimiters.

A word consisting of a question mark followed by a number
	?37
when runparsed (i.e., where a procedure name is expected), is treated as if it were the sequence
	( ? 37 )
making the number an input to the ? procedure. (See the discussion of templates, below.) This special treatment does not apply to words read as data, to words with a non-number following the question mark, or if the question mark is backslashed.

A line (an instruction line or one read by readList or readWord) can be continued onto the following line if its last character is a
	tilde ~ .
READWORD preserves the tilde and the newline; READLIST does not.

Line Continuation: An instruction line or a line read by READLIST (but not by READWORD) is automatically continued to the next line, as if ended with a tilde, if there are unmatched
	brackets, parentheses, braces, or vertical bars
pending. However, it's an error if the continuation line contains only the word END; this is to prevent runaway procedure definitions. Lines eplicitly continued with a tilde avoid this restriction.

If a line being typed interactively on the keyboard is continued, either with a tilde or automatically, Logo will display a tilde as a prompt character for the continuation line.

A semicolon begins a comment in an instruction line. Logo ignores characters from the semicolon to the end of the line. A tilde as the last character still indicates a continuation line, but not a continuation of the comment.

For example, typing the instruction
	print "abc;comment ~
	def
will print the word abcdef. Semicolon has no special meaning in data lines read by READWORD or READLIST, but such a line can later be reparsed using runParse and then comments will be recognized.

To include an otherwise delimiting character (including semicolon or tilde) in a word, precede it with
	backslash \ .
If the last character of a line is a backslash, then the newline character following the backslash will be part of the last word on the line, and the line continues onto the following line.
	To include a backslash in a word, use \\.
If the combination backslash-newline is entered at the terminal, Logo will issue a backslash as a prompt character for the continuation line. All of this applies to data lines read with READWORD or READLIST as well as to instruction lines. A character entered with backslash is equalP to the same character without the backslash, but can be distinguished by the backslashedP predicate. (However, BACKSLASHEDP recognizes backslashedness only on characters for which it is necessary:
	whitespace, parentheses, brackets, infix operators,
	backslash, vertical bar, tilde, quote,
	question mark, colon, and semicolon.)
An alternative notation to include otherwise delimiting characters in words is to enclose a group of characters in vertical bars. All characters between vertical bars are treated as if they were letters. In data read with READWORD the vertical bars are preserved in the resulting word. In data read with READLIST (or resulting from a parse or RUNPARSE of a word) the vertical bars do not appear explicitly; all potentially delimiting characters (including spaces, brackets, parentheses, and infix operators) appear as though entered with a backslash. Within vertical bars, backslash may still be used; the only characters that must be backslashed in this context are backslash and vertical bar themselves.

Characters entered between vertical bars are forever special, even if the word or list containing them is later reparsed with PARSE or RUNPARSE. Characters typed after a backslash are treated somewhat differently: When a quoted word containing a backslashed character is runparsed, the backslashed character loses its special quality and acts thereafter as if typed normally. This distinction is important only if you are building a Logo expression out of parts, to be RUN later, and want to use parentheses.

For example,
	print RUN (Se "\( 2 "+ 3 "\))
will print 5, but
	RUN (SE "make ""|(| 2)
will create a variable whose name is open-parenthesis. (Each example would fail if vertical bars and backslashes were interchanged.)

Example:

References:

Commandline option -run Debugging