alt.hn

2/21/2026 at 2:14:08 PM

Build Your Own Forth Interpreter

https://codingchallenges.fyi/challenges/challenge-forth/

by AlexeyBrin

2/24/2026 at 11:22:38 PM

I've been on/off working on a homebrew NES game. Pretty much the go-to environment for that is assembly, which I'm sure I could write if I were motivated, but I find assembly considerably un-fun so I wanted to use a higher-level language.

I had been looking for an excuse to learn Forth, and its use in classic computing meant that it had a shot of being workable on the NES.

I was initially using IceForth but I had trouble getting that working, and so I got Codex to generate something that works, but then I also that building your own Forth is sort of a rite of passage for a software engineer, so I have been building my own Forth from scratch.

My custom hack-job isn't ready yet, but I was extremely impressed at the performance I was able to get on the NES with compiled Forth from the Codex thing on the NES. I'm getting roughly 80% of the speed for equivalent programs written in assembly, with much less code and this is without advanced optimizations. I do plan on finishing my custom one because I think I can build what I want a bit better than Codex, and I'm optimistic I can get the performance reasonable.

Forth is such a fascinating language, because it sort of enables you to work at any level of the program. You can write it super high level, almost like Lisp, but you can also poke around and create mappings to assembly, and you can do all this with decent performance no less! It has quickly become one of my more favorite scripting languages, though that might be because I have always had a soft spot for RPN.

by tombert

2/25/2026 at 1:53:21 AM

I like building little throwaway FORTH interpreters as an exercise when learning a new language. They tend to touch just enough common programming needs to be interesting: read user input and/or a file, parse the input, run a state machine with two stacks, write output.

by SAI_Peregrinus

2/24/2026 at 10:00:02 PM

Video where I demonstrate how I explore JONESFORTH using GDB:

https://youtu.be/giLsd-bik6A?si=Gwm3NJdUzyrmmopH

by dharmatech

2/25/2026 at 12:27:29 AM

I enjoyed that! Nice intro to JonesForth and how it maps to assembly instructions.

by lioeters

2/24/2026 at 9:48:01 PM

I've already done that---ANS Forth for the 6809 (https://github.com/spc476/ANS-Forth).

by spc476

2/24/2026 at 10:13:10 PM

Advanced challenge: make it self-hosting.

by sophacles

2/25/2026 at 1:37:14 PM

In the past years, I developed a forth like language as an intermediate language for a C compiler. For debuging purposes, I also implemented a memory safe interpreter, besides a compiler that generates assembly output.

See my profile for link to my github repositories and look under MES-replacement for stack_c

by fjfaase

2/25/2026 at 4:27:43 PM

I’ve been working on a homemade CPU (in simulator) and I’m in the middle of implementing an ISA and assembler as a bug step up from working in machine code to working in assembly. I’ve been looking at Forth as a good option for a next-level-up language which is relatively easy to implement and easy to script with.

by alexthehurst

2/25/2026 at 6:12:45 AM

I wrote one some time ago, and it took me a lot longer than I thought it should. (it's core is finished, but dictionary is limited) https://ntavish.in/projects/emforth/

by ntavish

2/25/2026 at 7:40:05 AM

You might also enjoy this tutorial, which started out being based upon a hacker news thread:

https://github.com/skx/foth

I go through stages to implement minimal language.

by stevekemp

2/24/2026 at 9:18:57 PM

"if you know one forth, you know one forth"

by ithkuil

2/24/2026 at 9:30:22 PM

So implement four of them, and you will know them all! First Forth with indirect threaded code, second Forth with direct threaded code, third Forth with subroutine threaded code, and the final fourth with token threaded code.

by js8

2/24/2026 at 11:34:57 PM

You jest, but I did end up doing just that in my implementation (https://github.com/romforth/romforth) trying to shoehorn a Forth implementation into a MSP430 device with just 2KB ROM + 128 byte RAM

by romforth

2/25/2026 at 12:59:57 AM

Interesting. I have a slightly off topic question: do you agree that there are no good newbie programming manual for msp430? in comparison to Arduino or PIC etc

by iberator

2/24/2026 at 10:57:56 PM

I thought this was going to be a pun on the word "fourth", disappointed when I got to "final".

by n4r9

2/25/2026 at 6:46:13 AM

[dead]

by inigyou

2/24/2026 at 9:36:46 PM

I doubt you will want to code professionally in Forth unless you work on embedded, so the dialect you learn doesn't matter too much. But it is interesting to implement a small interpreter and play with it.

by AlexeyBrin

2/25/2026 at 2:33:34 PM

(I'm saying this with love)

by ithkuil

2/25/2026 at 5:35:48 AM

For some reason this site feels AI generated to me.

by fouc

2/24/2026 at 8:56:14 PM

[dead]

by umairnadeem123

2/24/2026 at 10:12:16 PM

[dead]

by kamlesh_nilesh

2/24/2026 at 9:35:24 PM

This is a strange article imo.

I was expecting to see FORTH in bare metal C or ASM.

There is a common myth about newbie programmers that FORTH is write-only and that you need to type everything in one line, without comments or function calls etc.

Writing forth is super easy especially if you have a stack machine at your disposal. For example when you are building your own virtual cpu/architecture with assembler and compiler.

It's more trivial than to understand any JavaScript framework lol

Research FORTH more guys - it doesn't need to be strange and hard :)

ps. Lisp SUCKS

/rant

by iberator

2/24/2026 at 9:50:49 PM

I was with you 'till the last line. :P

by volemo

2/24/2026 at 10:34:19 PM

IMO Lisp is harder to implement than Forth, and LESS readable, butt MAYBE i fell into the same trap as others with Forth. hahaha

by iberator

2/25/2026 at 12:54:38 AM

actually I think Lisp is easier to implement than Forth, buth is it really Forth if the internals aren’t discussed? (E.g. Word secondary, threaded code, etc)

by NetMageSCW

2/25/2026 at 5:47:27 AM

Forth does not specify threaded code. Implementation is left to the implementor.

Internally Forth can be direct threaded code, indirect threaded code, byte code, sub-routine calls or optimized native code.

by lebuffon

2/25/2026 at 3:07:54 AM

> There is a common myth about newbie programmers that FORTH is write-only and that you need to type everything in one line, without comments or function calls etc.

By contrast, in APL it's not a myth at all.

by EarlKing