May the Forth be With You

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 get_next function to get the next word. Make sure to skip the whitespace correctly.

http://beza1e1.tuxen.de/articles/forth.html

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.