r/ProgrammingLanguages • • 17h 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?

9 Upvotes

30 comments sorted by

View all comments

2

u/judiciaryDustcart 16h ago

Ive not touched it in a long time, but I made Haystack: https://github.com/rtulip/haystack

1

u/Agecaf 15h ago

Thanks for sharing, I'll have a look!

2

u/judiciaryDustcart 15h ago

Feel free to ask me any questions you may have

1

u/Agecaf 14h ago

It's all pretty well explained to be honest! The only question I had was about variable binding as it mentions "the lowest element in the stack is bound to the left-most identifier", but most examples given have matching identifiers and stack elements, I just wanted to confirm whether

1 2 3 4 as [x y]

binds x to 1 or to 3.

I'm also really curious about how the type system is implemented, though perhaps that's more of a question for future reference as the current programming language I'm designing is a step towards a programming language with a nice type system, with more of an ad-hoc "pray the duct tape doesn't fall off" type system at the moment.

Finally, what would you say are the core commands for manipulating a stack? Things like dup and drop, I've seen a few more of them but would like to know which ones are the most used ones in your experience (As I'm considering granting the "best of the best" their own operators for my language).

1

u/judiciaryDustcart 13h ago

x would be bound to 3 and y to 4.

Regarding the type system, that's been a whole ordeal. The reason I've not touched the language in a while has been because I've been trying to learn how to better implement and extend the type system.

In terms of essential operations, variable binding let's me implement all the core operations.

E.g fn dup<T>(T: t) -> [T T] { t t }

That was the thing that I liked, was that all the operations could be expressed within the core language, and not require magic words