stackforthconcatenative-language

Can a Forth-like language be implemented with just one stack?


Forth has a stack and a return-stack.

As far as I understand, the point of the return-stack is to store the previous values of the program counter.

C programs put the previous value of program counter on the stack, and use no return stack.

Does Forth only need a return-stack because it returns result(s) on the stack, and thus the previous value of the program counter could be buried?


Solution

  • The "Portable Assembly Language" should be close. It's a concept for a compiler for a language which is almost identical to standard/traditional Forth. There are some restrictions for which kind of programs can be written. Mostly, you have to avoid situations where the depth of the stack can't be statically determined.

    This language can be compiled in a way that only requires one stack.

    http://www.complang.tuwien.ac.at/anton/euroforth/ef13/papers/ertl-paf.pdf