In Forth we add new data types.
They must be accomodated by notations that result in a constant object.
This can always be accomplished by a compiling word that inspect the
next word in the source:
The basic idea is to add constant objects, sometimes called literals
or literal data by defining prefix words that parse the
remainder of the data, like so
Now 0x is a prefix and
0x4ABD12 is a denotation. Likewise for the string.
Note that the only difference with the previous solution is to leave out
the blank space following HEX: and ".
This is easy to implement, see my Forth implementation.
Instead of wanting an exact match with the word in the dictionary,
a literal is matched if its first part matches a prefix.
To examine an example (strings) in lina
Once this invention is made, regular numbers can be parsed using this
mechanism by defining 0..9 in the dictionary for
a net simplification of the Forth as a whole.
Strings starting with a blank was a constant source of confusion with the
Forth word S". Now it is just as you expect, and no different from
other computer languages.
Other Forth lectures
Go to the home page of Albert van der Horst