Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I "extend" the outer interpreter?

Tags:

forth

gforth

In different Forths, how do I customize the interpreter?

For example, in SP-Forth the interpreter always write the stack content and always make a CR/LF before printing:

1 2 3
 Ok ( 1 2 3 )
.s
1 2 3  Ok ( 1 2 3 )

I would like to see:

1 2 3  ok
.s 1 2 3  ok

And generally, I would like to be able to define new data inputs like

4-3i
{1,2,3,4,5}

The interpreter should then store the data as I defined in the extension. Also, on errors I would like soft stacks and variables to be reset.

Any ideas?

like image 278
Lehs Avatar asked Dec 07 '25 07:12

Lehs


1 Answers

In different Forth systems there are different ways for customization. In SP-Forth you can define another action for OK vector. For example, to avoid printing data stack state:

: OK2 ( -- ) STATE @ IF EXIT THEN ."  ok" CR ;
' OK2 TO OK
\ see the original definition in src/compiler/spf_translate.f

Though, it is difficult to avoid CRLF before "ok" in Windows console application since this CRLF is part of the text that you input.

Regarding a new data formats there is Recognizers RfD. It is implemented in some Forth systems, but not in SP-Forth yet.

In SP-Forth you can use NOTFOUND mechanism to add custom word format (words interpreter).

like image 161
ruvim Avatar answered Dec 11 '25 02:12

ruvim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!