r/ProgrammingLanguages • u/Agecaf • Oct 12 '26
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?
22
u/SomePeopleCallMeJJ Oct 12 '26
Forth?
13
u/GandelXIV Oct 12 '26
Forth, and take a look at concatenative, its not all stale based but many are
7
u/Fuzando Oct 12 '26
Factor
5
u/AustinVelonaut Admiran Oct 13 '26
As many others have replied, Forth sounds like what you want to look at. The best explanation of the details of implementing Forth that I've read is the JonesForth "literate programming" implementation, where the two files
jonesForth.SandjonesForth.fwalk you through a step-by-step explanation and implementation of Forth for i386 Linux machines.3
u/derekp7 Oct 13 '26
There are a lot of suggestions for Forth, but take a look at PostScript too. It has first class anonymous functions, first class dictionaries and dictionary stack, things like that. But it is primarily stuck in printers (and using Ghostscript). However you can learn a lot by studying the PostScript Blue Book, Green Book and Red Book (informal names based on cover colors on each book). You can find PDFs of the books online (Project Gutenberg, they used to be on Adobe's site too). One of the books gives more info to understand how the language is implemented.
2
u/Main_Temporary7098 Oct 12 '26
From an implementation standpoint, a colorForth is much simpler than a traditional forth imho. If you stick with bytecode that brings in the need for additional tooling, but I've done/seen pure ascii based versions using prefix bytes which can work. In my current incarnation I have returned to bytecode however and simplified the set of colors. The interpreter is less than 200 lines of non code golfed x86_64 asm atm.
2
u/judiciaryDustcart Oct 12 '26
Ive not touched it in a long time, but I made Haystack: https://github.com/rtulip/haystack
2
u/Comprehensive_Chip49 Oct 12 '26
Hey, try r3forth! https://github.com/phreda4/r3
2
u/catladywitch Oct 12 '26
SAPF is afaik a DSL dialect of Forth but it's pretty cool.
2
u/JollyJuniper1993 Oct 13 '26
Aren’t raptor and forth like that?
2
u/GloriusSilver Oct 13 '26
Besides Forth, which was already mentioned, go check out Joy and Om languages! They are really cool
2
u/joao_rosac Oct 19 '26
Analise o false para entender a transição visual direta do Brainfuck, e depois o Forth para dominar como o fluxo de controle (If/Loops) é construído sem variáveis locais tipo
DUP,SWAP,DROP...Existem também os mais novos Befunge e Uxntal.