Adding infix and parsing example.

This commit is contained in:
Brad Nelson
2025-01-25 09:31:27 -08:00
parent 0fc77179af
commit 53dfc659c3
4 changed files with 154 additions and 0 deletions

24
examples/infix/infix_generic.fs Executable file
View File

@ -0,0 +1,24 @@
#! /usr/bin/env ueforth
vocabulary infix infix definitions
variable pending
: token ( -- a ) >in @ tib + ;
: full? ( -- f ) >in @ #tib @ < ;
: ( token 0
begin full? over 0< 0= and while
token c@ [char] ( = if 1+ then
token c@ [char] ) = if 1- then
1 >in +!
repeat
drop token over - 1- 0 max
dup 0= pending ! evaluate ; immediate
: scarf bl parse evaluate
pending @ if postpone ( then ;
: enact state @ if , else execute then ;
: + scarf ['] + enact ; immediate
: - scarf ['] - enact ; immediate
: * scarf ['] * enact ; immediate
: / scarf ['] / enact ; immediate
forth definitions