'FOR READING SIMPLE SPACED WORDS
function Getword(string s,sys *i,*lw) as string
===============================================
sys ps = strptr s
byte b at (i-1+ps)
sys bi,ei
do
select b
case 0 : exit do
case 33 to 255 : exit do
end select
@b++
enddo
bi=@b
do
select b
case 0 : exit do
case 1 to 32 : exit do
end select
@b++
enddo
ei=@b
lw=ei-bi
i=ei-ps+1
if lw then return mid s,bi-ps+1,lw
end function
string tokerr
sys ert
string cr=chr(13,10)
function tokenise(string s) as string
=====================================
sys aw
sys lw
sys iw=1
sys it=1
string wr
string tok
do
wr=lcase getword s,iw,lw
if wr="" then exit do
if it>len tok then tok+=nuls 16000
aw=asc wr
select aw 'simple lookup
case "a"
if wr="any"
mid tok,it,"A" : it++
else
ert=1
end if
case "b"
if wr="brave"
mid tok,it,"B" : it++
else
ert=1
end if
case "c"
if wr="cat"
mid tok,it,"C" : it++
else
ert=1
end if
case else
ert=1
end select
if ert=1 then tokerr += "unknown " wr cr
ert=0
end do
return left tok,it-1
end function
function exec(string toks)
==========================
'JUMP BY TOKEN
sys t[256] : t[65]=>{@FAA,@FBB,@FCC}
'
sys e = len(toks)
sys i = 0
byte *b = strptr(toks)-1
sys eb = @b+e
NextItem:
@b++
if @b>eb then exit function
i=b : goto t[i]
'goto t[b]
FAA:
print "AA"
goto NextItem
FBB:
print "BB"
goto NextItem
'
FCC:
print "CC"
goto NextItem
end function
string toks=tokenise " any brave cat "
if tokerr then
print tokerr
else
exec toks
end if