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

21
examples/infix/parsing.fs Normal file
View File

@ -0,0 +1,21 @@
: kind ( "name" -- )
create 0 ,
does> @ begin dup while
state @ >r here >r >in @ >r
dup >r @ catch 0= if rdrop rdrop rdrop rdrop exit then
r> cell+ @
r> >in ! r> here - allot r> state !
repeat
-1 throw ;
: :{{ >body :noname ;
: {{ latestxt :{{ ;
: }} postpone ; here >r , dup @ , r> swap ! ; immediate
: @token ( -- ch ) >in @ tib + c@ ;
: +token 1 >in +! ;
: =token ( ch -- ) @token <> throw +token ;
: within ( ch a b ) >r over <= swap r> <= and ;
: []token ( a b -- ch ) @token -rot within 0= throw @token +token ;
: t' postpone [char] postpone =token ; immediate
: stoken ( a n -- ) 0 ?do dup c@ =token 1+ loop drop ;
: t" postpone s" postpone stoken ; immediate