FORTH-ish interpreter
Go to file
2021-02-22 16:55:33 -05:00
.gitignore initial commit; we have evaluation! 2021-02-13 21:09:56 -05:00
builtins_test.go tests, abstracting output for PRINT and EMIT 2021-02-20 12:09:04 -05:00
builtins.go remove unused DIVMOD builtin 2021-02-21 15:06:08 -05:00
eval.go fix silly word collision with -1 built-in 2021-02-21 15:04:51 -05:00
flags.go tests, abstracting output for PRINT and EMIT 2021-02-20 12:09:04 -05:00
go.mod initial commit; we have evaluation! 2021-02-13 21:09:56 -05:00
main.go fix silly word collision with -1 built-in 2021-02-21 15:04:51 -05:00
mem_test.go initial commit; we have evaluation! 2021-02-13 21:09:56 -05:00
mem.go initial commit; we have evaluation! 2021-02-13 21:09:56 -05:00
README.md fibonacci code 2021-02-22 16:55:33 -05:00
stack_test.go make IF/ELSE/THEN work! 2021-02-20 15:52:27 -05:00
stack.go make IF/ELSE/THEN work! 2021-02-20 15:52:27 -05:00
words_test.go make IF/ELSE/THEN work! 2021-02-20 15:52:27 -05:00
words.go make IF/ELSE/THEN work! 2021-02-20 15:52:27 -05:00

Prosper

Prosper is a Forth-like stack-based language. While taking specific influence from Forth, it does not attempt to emulate or implement the ANS Forth standards.

Currently, the language is entirely interactive -- to explore, simply run go run . in the root of this project and an interactive session will begin.

Syntax

Prosper is stack-based, as mentioned, so all the standard stack semantics are present:

> 1 2 3 4 + * -
ok
> .
-13 ok

New words can be defined using : ;:

> : SQUARE DUP * ;
ok
> 10 SQUARE .
100 ok

It has a single loop construct, DO LOOP:

> : TOFIVE 5 0 DO I . LOOP ;
ok
> TOFIVE
0 1 2 3 4 ok

Branches using IF ELSE THEN work:

> : EMOJI 0 < IF 128201 EMIT ELSE 128200 EMIT THEN ;
ok
> 100 EMOJI 
📈 ok
> -100 EMOJI
📉 ok

Here's a Fibonacci implementation:

> : FIB 2DUP + ;
ok
> : FIBN 0 1 ROT 1 DO FIB ROT DROP LOOP SWAP DROP ;
ok
> 10 FIBN .
55 ok

And, of course, it knows how to quit:

> BYE
bye

Future Plans

  • Implement VARIABLE and CONSTANT and the various ? ! @ related words
  • Implement SEE
  • Implement loading libraries of pre-written functions both from the command-line and at run-time
  • Add much better readline behaviors in the interactive console (up-arrow for history, cursor movement...)