Interpreter for a massively simplified version of Forth.
I originally wrote this as a solution to an exercism.io exercise, but had so much fun that I decided to take it a bit further.
Basic integer arithmetic operations:
+: add last two items-: subtract last item from second to last item*: multiply last two items/: divide second to last item by last item
Stack manipulation operations:
DUP: duplicate the last itemDROP: remove the last itemSWAP: swap the order of the last two itemsOVER: duplicate the second to last item
Output:
.: print the last item as an integer.s: print the stack without consuming itEMIT: print the last item as a unicode character
It also supports defining new words at runtime:
: word-name definition ;
$ go install github.com/fordhurley/thorf/cmd/thorf
$ thorf -e "1 2 + ."
3
$ thorf testdata/helloworld.fs
Hello, world!
$ echo "6 4 - ." | thorf
2