Skip to content
massively simplified forth interpreter
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd/thorf
testdata
LICENSE
README.md
lexer.go
operation.go
stack.go
stack_test.go
thorf.go
thorf_test.go

README.md

thorf

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.

Supported "words"

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 item
  • DROP: remove the last item
  • SWAP: swap the order of the last two items
  • OVER: duplicate the second to last item

Output:

  • .: print the last item as an integer
  • .s: print the stack without consuming it
  • EMIT: print the last item as a unicode character

It also supports defining new words at runtime:

: word-name definition ;

Executable

$ go install github.com/fordhurley/thorf/cmd/thorf
$ thorf -e "1 2 + ."
3
$ thorf testdata/helloworld.fs
Hello, world!
$ echo "6 4 - ." | thorf
2
You can’t perform that action at this time.