A Forth interpreter in JavaScript that fits in a few dozen lines

Writing a primitive Forth in JavaScript (2024)

A Forth interpreter in JavaScript that fits in a few dozen lines

A first-person account of building a primitive Forth interpreter in JavaScript with p5.js, using a character array instead of strings to mirror low-level implementations. It covers the two core data structures, a data stack and a words dictionary, plus word search, word call, token parsing, and the evaluation loop where compile mode turns words into composites of other words. The author later ported the ideas to ARM and a personal bare-metal environment.

This prototype was quite eye opening to me as I realized the brilliance of Forth design and practicality while writing it.
  1. veltas

    I think the first question I've got for JavaScript Forths is how you'd handle addresses, bytes, etc., because that's a staple of any conventional Forth, necessary to create tables, arrays, and handle strings. There are lots of ways of doing it but there are some nasty compromises required for a more standard-looking Forth.

  2. bitwize

    "Writing things in a programming language" now seems to have the same quirky old-internet charm as "Flash games".

More from this day

2026-12-01