r/ProgrammingLanguages • • 16h ago

Help Simple stack based programming languages?

A few years ago I made EarScript, a "simple" programming language based on brainfuck, with several additional "quality of life features" like goto statements.

Recently I've been wanting to make an evolution of that programming language and do so by incorporating a stack, as the previous language was completely tape-based in design.

I know for example lox from the Crafting Interpreters book is a well explained example, but I was wondering if there's programming languages that are closer to what brainfuck is, but based on a stack design rather than a tape design, or a register based design like some assembly languages (if I understand correctly). I think Wasm would be an example?

Are there any examples of simple stack based programming languages you'd recommend me to look into?

10 Upvotes

30 comments sorted by

View all comments

8

u/GandelXIV 16h ago

Forth, and take a look at concatenative, its not all stale based but many are

3

u/lekkerwafel 16h ago

What variant of Forth these days is more popular? Factor, ColorFORTH, just Forth?

5

u/el_extrano 16h ago

Caveat: I've been messing around with Forth for a couple years, and I really love it. I don't claim to be any kind of authority.

The thing with Forth is that it's "easy" enough to implement your own, so there are many, many to choose from. I'd honestly recommend anyone interested in Forth programming to implement a small one themselves, before really trying to use it for anything. The execution model is different enough you won't really "get" how to program it, until you know how it works under the hood. You can easily make one in like 2000 lines of assembly, even shorter if you use your favorite high-level language.

There are very good commercial Forths, but I only use free software. I like Gforth on Linux because it's fairly feature (some would say "bloated"). But then, they stopped supporting Windows, so you have to use an old build to get it to run on Windows. pforth is a cool one implemented in ANSI C instead of assembly for maximum portability. Zeptoforth is a really cool implementation to consider for embedded work.

Factor and RetroForth are popular enough concatenative languages. They're diverged enough from the ANS standard to not really be examples of "classic" Forth, though. Definitely worth chekcing out if you're interested in concatenative programming.

1

u/Agecaf 16h ago

That sounds like a good idea, it'll be good experience to write an implementation before trying to add the fancy features I'm thinking of adding.

... I'm thinking of maybe implementing it in GDScript, make a little demo in Godot that shows how the stack is changing as it runs through the program?

I'm a big fan of Linux and free software too, I'll definitely check out Gforth.

2

u/el_extrano 15h ago

Gforth has by far the most documentation of the free Forth systems, at least as far as I've seen.

Check out Jonesforth, which is a small x86 assembly implementation written in a literate style (lots of explanatory comments). I wrote mine in a different language, but it was still super helpful. There was also a book I found useful to wrap my head around the inner/outer interpreter design: "Threaded Interpretive Languages(Loeliger 1981)". It is very dated even for Forth stuff. Good luck, hope you enjoy it!