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.
Exercise 1
Read Forth code from some input stream. There shall be a
http://beza1e1.tuxen.de/articles/forth.htmlget_next
function 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 Sequence
and IteratorProtocol
and the get_next
function mentioned above is next() -> MyForth.Word?
The code is here:
https://bitbucket.org/jeremy-pereira/myforth/commits/tag/blog-970