Skip to content

massively simplified forth interpreter

License

Notifications You must be signed in to change notification settings

fordhurley/thorf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

massively simplified forth interpreter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published