eigenhombre / toobeci

Yet Another Forth Interpreter Written in Go (YAFIWIG)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

toobeci

build

A simple Forth interpreter written in Go. Mostly just to help me learn both languages better.

To run it, install Go, clone this repo, and work from within the directory. Example session follows.

$ go build .
$ go install
$ toobeci
Welcome to toobeci

> \ comments are ignored
> \ . prints the 'top of the stack':
> 1 .
1
> \ you can do math ...
> 1 2 +
> \ and then show the result:
> .
3
> 10 10 / .
1
> 10 dup dup * * .
1000
> 2 3 drop .
2
> 42 emit
*
> \ The `emit` operator emits unicode characters:
> 27700 emit
水
> clr      \ clears the stack
> .s       \ shows the stack
> 1 2 3 .s
	3
	2
	1
> swap .s  \ swap top two items
	2
	3
	1
> rot .s   \ rotate items
	1
	2
	3
> over .s  \ copy & promote 2nd item
	2
	1
	2
	3
> \ Some boolean logic:
> 1 1 and .
1
> 1 0 and .
0
> 1 1 or .
1
> 1 0 or .
1
> \ Default 'true' value is -1 (0b1111...):
> 1 1 = .
-1
> 1 0 = .
0
> 3 not .
0
> 0 not .
-1
> dakine
unknown word: dakine
> ^D
Goodbye.

These examples were autogenerated from the tests in main_test.go.

Supported operators:

+ * / - = rot dup drop swap over . .s emit clr and or not

Up Next

  • if
  • ?DO ... LOOP
  • begin
  • @
  • !
  • s" ...
  • :

...

About

Yet Another Forth Interpreter Written in Go (YAFIWIG)


Languages

Language:Go 84.8%Language:Forth 6.7%Language:Python 4.2%Language:Dockerfile 2.2%Language:Makefile 2.1%