Defining words
Factor handbook » The language » Parsing words

Prev:Nested structure
Next:Parsing raw tokens


Defining words add definitions to the dictionary without modifying the parse tree. The simplest example is the SYMBOL: word.

The key factor in the definition of SYMBOL: is scan-new, which reads a token from the input and creates a word with that name. This word is then passed to define-symbol.
scan-new ( -- word )

scan-new-word ( -- word )


Colon definitions are defined in a more elaborate way:
:


The : word first calls scan-new, and then reads input until reaching ; using a utility word:
parse-definition ( -- quot )


The ; word is just a delimiter; an unpaired occurrence throws a parse error:

There are additional parsing words whose syntax is delimited by ;, and they are all implemented by calling parse-definition or parse-array-def.