
Finite State Machines in Forth (1995) - nprescott
http://galileo.phys.virginia.edu/classes/551.jvn.fall01/fsm.html
======
nprescott
With the veritable flurry of state machine posts today[0,1] I thought I'd
(re)submit[2] one of my favorite posts on finite state machines in Forth.

The specific example is of _number input routine allows signed decimal numbers
without power-of-10 exponents (fixed-point, in FORTRAN parlance)_ and comes
from the author's book Scientific Forth, where a fuller example is used _...
to determine whether a piece of text is a proper identifier (that is, the name
of a variable, subroutine or function) according to the rules of FORTRAN._

I originally heard of Scientific Forth from _Programming in the Twenty First
Century_ where it made a list of "Five Memorable Books about Programming"[3]
with the following description:

 _Dr. Noble demonstrates how he uses Forth for hardcore matrix work and, when
he realizes that RPN notation isn 't ideal in all circumstances, develops a
translator from infix expressions to Forth._

[0]:
[https://news.ycombinator.com/item?id=22746708](https://news.ycombinator.com/item?id=22746708)

[1]:
[https://news.ycombinator.com/item?id=22748785](https://news.ycombinator.com/item?id=22748785)

[2]: previously 3, 6 and 8 years ago, never any comments:
[https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...](https://hn.algolia.com/?dateRange=all&page=0&prefix=true&query=%22finite%20state%20machines%20in%20forth%22&sort=byPopularity&type=story)

[3]: [https://prog21.dadgum.com/19.html](https://prog21.dadgum.com/19.html)

~~~
nyankosensei
A project to create a Creative Commons version of Dr. Noble’s book was
started, but doesn’t seem very active lately [0]. The lead even received
permission from Dr. Noble’s widow [1].

[0]
[https://github.com/Josefg/Scientific_FORTH](https://github.com/Josefg/Scientific_FORTH)
[1]
[https://github.com/Josefg/Scientific_FORTH/blob/master/Conse...](https://github.com/Josefg/Scientific_FORTH/blob/master/Consent.txt)

~~~
nprescott
I've helped out with a few chapters! I'm actually very excited about it due to
the relative scarcity of physical copies of the book.

While it isn't too active, the most recent activity was in the last week or
so, I think all that remains are some figures and tables for a couple
chapters, the index and proof-reading[0]. It's very nearly there due to a lot
of work on Josef's part.

[0]:
[https://github.com/Josefg/Scientific_FORTH/wiki](https://github.com/Josefg/Scientific_FORTH/wiki)

------
hangonhn
FSM is something I've always been curious about but I can't seem to find any
good intro on. Does anyone have a good recommendations? I sort of don't want
one tied to a specific language but rather one that helps me understand it
from a conceptual level.

Thanks!

~~~
bear8642
Hopcroft Ullman's _Introduction to Automata Theory, Languages and Computation_
has good section on state machines and their connection to Regular Expressions

~~~
hangonhn
Thank you!!! Its relationship to regex is actually precisely the part that
piqued my interest.

~~~
brudgers
With automata theory it’s useful to be pedantic. What people ordinarily mean
by “regex” are in different classes of automata from regular expressions as
equivalent to finite state machines. For example Perl capture groups, look
ahead, and backtracking are beyond what a finite state machine or its
equivalent regular expression is capable of. Though for me the simplicity of
the FSM is a big part its intellectual appeal.

------
DonHopkins
I always thought Go Corporation should have made a mathematically focused
FORTH dialect called "GoFORTH&*”, to bring FORTH abundantly in the earth.

------
NieDzejkob
I'm trying to follow the code in "The Best FSM so far", and I can't see the
moment where offset-to-action is added to the base address of the FSM like in
the previous examples. Shouldn't there be a `R@ +` after `CELLS`?

------
carapace
This is great! (but maybe put a (1995) on the title?)

~~~
capableweb
Forth is mentioned in the title, do you really need to add that it's before
the 2000's if that's the case? ;)

~~~
bear8642
Forth is still alive and kicking!

~~~
capableweb
Of course! Have friends who work with it on a daily basis. My comment was
mostly tongue in cheek, didn't mean that Forth is completely dead. Usually
when seeing Forth though, it's bit older stuff than say PHP. My friends for
example, are stuck trying to refactor very old code, written in Forth.

Didn't mean no harm :)

~~~
macintux
What do your friends do with it? It’s very high on my priority list for new
languages to learn, and finding a job with it someday would be very
interesting.

~~~
carapace
Be sure to read "Thinking Forth". Even if you don't wind up doing a lot with
Forth it will still improve your abilities as a programmer.

[http://thinking-forth.sourceforge.net/](http://thinking-
forth.sourceforge.net/)

~~~
macintux
It's in my pile o' papers. I've broken it out a couple of times but haven't
gotten far yet.

