string src=quote
--NorwegianParrotScript--
aa = (b+c)*d
--NorwegianParrotScript--
'print a
'state variables
'===============
sys ascw, 'ascii code of first word char
ascn, 'ascii code of next word or end of line
lenw, 'length of word
swd, 'start index of word
ewd, 'boundary index of word
dtp, 'dot position
tyw, 'type of word
opr, 'operator code
opn 'operand code
function nword(string s,sys *i)
'==============================
sys pt=strptr(s)
sys b,e,p
dtp=0
tyw=0
p=pt+i-1
byte a at p
'
'skip leading space and lines
'
do
select a
case 0
exit do
case 33 to 255
exit do
end select
p++
end do
b=p-pt+1
ascw=a
swd=b
'
'locate boundary of word
'
'quotes
'
if ascw=34 or ascw=96 then 'or ascw=39 ''
if tyw=0 then tyw=3
do
p++
if a=ascw then goto endnword
end do
end if
do
select a
case 0 to 32
exit do
case 46
if dtp=0 then
dtp=pt-p+1 'DOT position
end if
p++ : continue do
case 48 to 57
if tyw=0 then tyw=1
p++ : continue do 'NUMS
case 65 to 90
if tyw=0 then tyw=2
p++ : continue do 'CAPS
case 96 to 122
if tyw=0 then tyw=2
p++ : continue do 'LOWERS
case 95
if tyw=0 then tyw=2
p++ : continue do 'UNDERSCORE
case 33 to 47
e=p-pt+1
if b=e then
tyw=4 'symbol !%& etc
p++
end if
exit do
case 58 to 64
e=p-pt+1
if b=e then
tyw=5 'symbol ;:<=>?@ etc
p++
end if
exit do
case 91 to 96
e=p-pt+1
if b=e then
tyw=6 'symbol [\] etc
p++
end if
exit do
case 123 to 126
e=p-pt+1
if b=e then
tyw=7 'symbol {|}~ etc
p++
end if
exit do
end select
p++
end do
'
endnword:
'--------
'
e=p-pt+1
ewd=e
'
'skip to next word or end of line
'
do
select a
case 0
exit do
case 10
exit do
case 13
exit do
case 33 to 255
exit do
end select
p++
end do
ascn=a
lenw=e-b
i=p-pt+1
end function
'states of tyw
'=============
' 1 numbers
' 2 upper case
' 2 lowercase
' 3 quote
' 4 symbols
' 5 symbols
' 6 symbols
' 7 symbols
function identify(s,i)
'=====================
if lenw=1
if tyw>3
opr=ascw
select case ascw
case "+"
if ascn=43 then
opr+=0x200
elseif ascn=61
end if
case "-"
if ascn=45
opr+=0x200
elseif ascn=61
opr+=0x100
end if
case "*"
if ascn=61
opr+=0x100
end if
case "/"
if ascn=61
opr+=0x100
end if
case "<"
if ascn=61
opr+=0x100
end if
case "="
case ">"
if ascn=61
opr+=0x100
end if
case ","
case ";"
case ":"
case "?"
case "@"
case "("
case ")"
case "["
case "]"
case "{"
case "}"
end select
exit function
end if
end if
end function
string cr,tab,pr
cr=chr(13)+chr(10)
tab=chr(9)
pr="WORDS AND WORD-TYPE:" cr cr
function ProcessScript(string s)
'===============================
string wr
sys i=1
do
opn=0
opr=0
nword s,i
identify s,i
wr=mid src,swd,lenw
if lenw=0 then exit do
pr+=wr tab tyw cr
end do
print pr
end function
ProcessScript src