rforth is an experimental implementation of an interpreter for the Forth programming language written in Python. It's not pretty but it's mine.
Presently it only includes a shell for playing. I don't have any real plans for the future with this thing.
It's pretty brittle, it's really not designed for use by other humans at the moment but feel free to have a play
The following code counts down from whatever is at the top of the stack.
: loop 1 swap - dup dup . 0 = if else loop then ;
The program has a parameter to preload a file as a standard library of words defined with rforth.
Pops the top two items on the stack and adds two of both back on.
Combines the output of > or =
Combines the output of < or =
Pops the top two items on the stack and then puts the result back on top.
Pops the top two items on the stack and then puts the result back on top.
Pops the item on top of the stack and prints it as an integer
Quits the interpreter
Prints the item on top of the stack as an ASCII character
Enters word compile mode
Exits word compile mode.
Prints the stack out for debugging
Prints all user defined words for debugging
Pops the top two items on the stack, compares the top value (a) to the next value (b) and puts -1 on the stack if a > b, and 0 on the stack if b > a.
Pops the top two items on the stack, compares the top value (a) to the next value (b) and puts -1 on the stack if a < b, and 0 on the stack if b < a.
Pops the top two items on the stack, compares the top value (a) to the next value (b) and puts -1 on the stack if a = b, and 0 on the stack if b != a.
Pops the top item on the stack, compares it to -1 and if they are equal, executes the code between either if and else or if and then, depending on if there is an else statement defined. If the top value on the stack is not -1, it executes the else block.
Pops the top item on the stack and adds two of it back on.
Pops the top three items on the stack (a,b,c) and puts them back in the order (c,a,b)
Pops the top two items on the stack (a,b) and puts them back in the order (b,a)
Pops the top two items on the stack and puts -1 on the stack if either value is -1.
Pops the top two items on the stack and puts -1 on the stack if both values are -1.
Pops the top two item (k,v) on the stack and puts v in position k on the heap.
Pops the top item (k) on the stack and then inserts the value in position k on the heap into the top of the stack.
Prints the heap out for debugging.
Sets the "reading string" flag until it reaches a closing quotation mark. Reads the inputted string on to the stack.
https://en.wikipedia.org/wiki/Forth_(programming_language)
https://tildegit.org/rmgr/rforth