In which I write a simple word parser
My project for the weekend is a Forth interpreter. I stumbled across a web site that tells you how to write one. I say “interpreter” because a compiler involves messy things like machine code and I don’t want to go there just yet.
Read Forth code from some input stream. There shall be ahttp://beza1e1.tuxen.de/articles/forth.html
get_nextfunction to get the next word. Make sure to skip the whitespace correctly.
I actually started by getting a copy of gforth to give me something as a reference point. I downloaded it using Macports.
The input parser is pretty simple. All it does is take an input stream of characters (modelled by a
Character iterator) and chop it up into words based on white space.
InputParser conforms to
IteratorProtocol and the
get_next function mentioned above is
next() -> MyForth.Word?
The code is here: