In which I comment on things
Define words
http://beza1e1.tuxen.de/articles/forth.html(
and)
in Forth. Make(
read words until)
and do nothing with them. This is how Forth implements comments.
I didn’t quite follow the prescription above. I found that gforth will happily parse things like 3 ( 4 hgfd) .
and (in this case) return 3
. So it is not a case of just ignoring words until you get the )
but ignoring characters until you see the )
character.
My implementation endows InputParser
with a comment character, which if not nil
causes it to discard all characters in its input stream up to and including the comment character. It then emits )
to close the comment. The words (
and \
simply set an appropriate comment character and the word )
sets the comment character to nil
.
The code is tagged blog-1061.
You will notice from the commits the I have made some other changes. For example, I added code in to allow me to dump the contents of the dictionary for debugging purposes. I’ve also finally made words case insensitive, so you can now type dup
or DUP
or dUp
which is in line with many Forth implementations.