Author Topic: Word parser for Basic  (Read 2315 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4330
    • Oxygen Basic
Word parser for Basic
« on: February 04, 2013, 01:48:39 AM »

Handles symbols and quotes as well as alphanumeric words

Code: OxygenBasic
  1.   function getword(s as string, b as sys) as string
  2.   '================================================
  3.  'b=1
  4.  sys a,c,d,bb,bc
  5.   a=0
  6.   bb=b
  7.   do
  8.     c=asc s,b
  9.     if c=0 then exit do
  10.     if c>32 then exit do
  11.     b+=1
  12.   end do
  13.   bc=b
  14.   if c=34 or c=96 then 'quotes
  15.    do
  16.       b+=1
  17.       d=asc s,b
  18.       if d=0 or d=c then b+=1 : jmp fwd done
  19.     end do
  20.   end if
  21.   do
  22.     c=asc s,b
  23.     select c
  24.     case 0 to 32 : exit do
  25.     case 33 to 47
  26.       if c=35 then jmp fwd more '#
  27.      if b=bc then b+=1
  28.       exit do
  29.     case 48 to 57 : jmp fwd more 'numbers
  30.    case 58 to 64
  31.       if b=bc then b+=1
  32.       exit do
  33.     case 65 to 90 : jmp fwd more 'capitals
  34.    case 91 to 96
  35.       if c=95 then jmp fwd more 'underscore
  36.      if b=bc then b+=1
  37.       exit do    
  38.     case 97 to 122 : jmp fwd more 'lower case
  39.    case 123 to 127
  40.       if b=bc then b+=1
  41.       exit do
  42.     end select
  43.     '
  44.    'higher ascii chars treated as part of word
  45.    '
  46.    more:
  47.     '
  48.    b+=1
  49.   end do
  50.   '
  51.  done:
  52.   '
  53.  if b>bb then return mid s,bb,b-bb
  54.  
  55.   end function
  56.  
  57. 'TEST
  58.  
  59.  
  60. sys    i=1
  61. string wd,pr
  62. do
  63.   wd=getword("abc(d[xx]+7/6,`qwerty`)",i)
  64.   if not wd then exit do
  65.   pr+=wd+chr(13,10)
  66. end do
  67. print pr
  68.