

  '===========================
  'SUBROUTINES FOR TRANSLATE()
  '===========================


  subroutine errordetails
  =======================

  if ow
    ers+="WORD: "+htb+ow+cr
  endif
  '
  if funi
    ers+="PROC: "+htb+wn+cr
  endif
  '
  a=sttw-sttl+1
  if a<1
    a=1
  endif
  ers+="COL: "+htb+str(a)+cr
  '
  ers+="LINE: "+htb+lnmks+cr
  '
  if cfile
    ers+="FILE: "+htb+cfile+cr
  endif
  '
  end subroutine


  ==========================
  subroutine procedurerecord
  ==========================
  '
  w4=lnmks
  '
  'PROCEDURE HEADER
  '
  if nd=18
    if funi>0
      ert=160 : ers="nested procedure" : ret
    endif
  else
    if funi>0
      ert=161 : ers="nested declaration" : ret
    endif
    funi=1
    typp=cpuw
    noin=0 'itr global noin?
    funn=0
    lcl=0
    lcls=0
    mlcl=0
    plcl=0
    blcl=0
    funl=0
    flbl=0
    dcs=0
    dts=0
  endif 'nd<>18
  if atx
    atf=1
  else
    atf=0
  endif
  if (cpuw=8)and(ccx=0)
    ccp=3 '64BIT INTERNAL CALLING CONVENTION
  else
    ccp=ccx
  endif
  crgd=crg
  '
  wva(1)="" : wva(2)=""      'CLEAR STATE
  if cpuw=8
    for a=1 to 4
      typl(a)=0 'CLEAR PARAM TYPES (CHECKING FOR FLOAT)
      typq(a)=0 'PARAM EXCESS SIZE
    next
  endif
  '
  if nd=18
    w1=wordahead(s,i) 'DECLARE
    if idword(" function sub ",w1)
      i=nwd
    endif
    skiplspace(s,i)
    pf+=isptr(s,i) 'FUNCTION POINTER
  endif
  '
  icas=1 : ilc=1 : ali=bword(s,i)  'PRIMARY (ALIAS) NAME
  wn=ali
  '
  'POSSIBLE ALIAS AS FIRST TERM
  '(IHEADERS ONLY)
  '
  if nd=18
    if asc(ali)=34
      ali=noquotes(ali) 'REMOVE QUOTES
    endif
    a=instr(ali,"@")
    if a 'DERIVE NAME FROM MANGLED ALIAS
      if asc(ali)=95
        b=2
      else
        b=1 'strip leading underscore
      endif
      wn=mid(ali,b,a-b)
    endif
  endif
  '
  clcase(wn) 'CASE CONVERTED NAME
  '
  skiplspace(s,i)
  '
  if vew>0
    if(nd>=11)and(nd<=13)
      appendt(cr+cr+ucase("'"+wr+" "+wn)+cr+cr)
    endif
  endif
  '
  c=0
  '
  do
    if isxn
      exit do
    endif
    '
    'ALIAS AS SECOND TERM
    '
    if isq(ascn)
      ali=noquotes(tword(s,i))  'IMPLICIT ALIAS
      continue do
    else
      w1=wordahead(s,i)
      a=dic(" lib 1, alias 2, ",w1)
      if a=1
        i=nwd
        lby=rootpath(lpath+lexiword(s,i)) 'EXPLICIT LIBRARY
        continue do
      elseif a=2
        i=nwd
        ali=noquotes(tword(s,i)) 'EXPLICIT ALIAS
        continue do
      endif
    endif
    a=readcc(w1,ccp)
    if a
      i=nwd
      continue do
    endif
    exit do
  loop
  '
  funm=ali    'remember original name
  lnmks=w4 : w4=""  '
  if nd=13
    pn=1 'offset allowing for 'this'
  endif
  '
  if nd=18
    if lby=""
      lby=libr 'POSSIBLE DEFAULT LIBRARY NAME
    endif
    skiplspace(s,i)
  else
    lby=""
  endif
  '
  string was=""
  '
  'LOOKAHEAD FOR BRACKETS IN PROTOTYPE
  '
  =======
  lookbr:
  =======
  a=i
  nextinstruct(s,i)
  if ascn=40 
    'if cpuw=8 '8 for 64bit 'and nd<18
      'capture(s,a,i,0)
      'w2=mid(s,a,i-a)
      'i=a
      'inserts(s,w2,i)
      i++
      nextinstruct(s,i)
      bpb=1 : gosub parsedim 'READ PROTOTYPE PARAMS
    'else 'cpuw=4 '32bit
    '  capture(s,a,i,0)
    '  w2=mid(s,a,i-a)
    '  w2=buildsig(w2,2,nd) : w4=sigv : ws="" : dfv=1
    '  'w2=buildsig(s,i,nd) : w4=sigv : ws="" : dfv=1
    'ndif
    b=-5
  elseif wordahead(s,i)="as"
    a=i
    i=nwd
    was=tword(s,i)
    isptr(s,i)
    was=" "+mid(s,a,i-a)+" "
    goto lookbr
  else 'NO BRACKETS
    if nd=18
      b=-4 'ASSUME UNPROTOTYPED
    else
      b=-5
    endif
  endif
  '
  if was
    inserts(s,was,i)
  endif
  '
  mrcin me
  w1="" : w5="" : w6=""
  w2=sigs+sigd
  w9=wn+sigs 'OVERRIDEN FOR 'AT' VECTORS AND LIBRARY CALLS
  int dtx=etx 'TO EXPORT ONCE ONLY
  '
  do 'rqualpro:
  '============
  '
  a=i
  nextinstruct(s,i)
  if ascn=44
    i++ : continue do 'SUPPORT COMMA SPACING
  endif
  w1=wordahead(s,i)
  int aa
  aa=readcc(w1,ccp)
  if aa
    i=nwd
    continue do
  endif
  d=dic( " as 1, export 2, extern 3, external 3, callback 3, link 4, at 5, = 5, label 6, nosig 7, ",w1)
  '
  if d
    swd=i
    i=nwd
  else
    i=a : skiplspace(s,i)
    if dtx
      d=2 'DEFAULT EXPORT
      dtx=0
    else
      w1="" : exit do
    endif
  endif
  '
  select d
  '=======
  '
  case 1 'AS TYPE
    '
    'RETURNVAR
    w5=tword(s,i)
    a=identype(w5)
    d=isptr(s,i) 'RETURNING POINTERS (SWALLOW)
    if nd<>18
      lcl=1
    endif
    '
    if a=0x10 'VOID OR HIGHER TYPE POINTERS
      if d>0
        d-- : w5="sys" : a=cpuw
      else
        w5="" : a=0
      endif
    endif
    '
    'ASSUME HIGHER TYPES IMPLICITLY RETURN A POINTER
    '       
    'if a>=typh
      '
    if a>=0x100
      '
    elseif a>=0xc0
      if nd<>18
        lcl=1 : lcls=1 'GARBAGE COLLECTION
      endif
    elseif a>=0xa0
      if d=0
        a and=0x1f 'RETURN TYPE AS BYTE OR WORD (C direct char)
        w5=identypes(a)
      else
        if nd<>18
          lcl=1 : lcls=1 'GARBAGE COLLECTION
        endif
        'not w5+=string(d,"*")
        d--
      endif
    endif
    '
    if d
      w5+=string(d,"*") : a=cpuw 'POINTER RETURN TYPE
    endif
    wva(1)=w5
    typp=a
    d=0
    '
    case 2 'EXPORT
    '
    'ADD TO EXPORT TABLES
    '--------------------
    '
    'exluding declared functions and methods
    if nd=18
      if asc(w9)=91 '[vector]
        'EXPORT OOP METHOD AS A FUNCTION WITH HANDLE PARAM
        'declare mm at @cc.mm, export
        appendt "jmp fwd _njmp_ : ."+wn+" : jmp "+w9+" : ._njmp_"+cr
        exportadd(wn,ali,eord)
      endif
    elseif nd<>13 'method nd=13
      exportadd(wn,ali,eord)
      atf=1
    endif
    dtx=0 'SUPPRESS DEFAULT EXPORT
    '
  case 3 'EXTERN / EXTERNAL / CALLBACK
    '
    atf=1
  case 4 'LINK
    '
    'IN  ARRAY OR PROCEDURE HEADER
    'GIVE PROCEDURE POINTER TO EXTERNAL OR INTERNAL VARIABLE
    'OR PROVIDE FUNCTION ADDRESS FOR HOST    
    '
    skiplspace(s,i)
    '
    if ascn=35
      atf=1 'AUTOMATICALLY SET AS EXTERNALLY ACCESSIBLE PROC
      w6=tword(s,i)
      sys p=getvarptr(w6)
      if not p
        ers="Host link not found" : ert=4005 : ow=w6
      endif
      w6="["+str(p)+"]" : wpfx="" '..link #hv
    else
      w6=pword(s,i) ' link a  link a[2]  link *a ...
    endif
    '
    if nd=18
      if lby  'LINKAGE FROM IMPORT LIBRARY
        c=addlib(lby)
        w1=addlproc(c,ali)
        w1=operi(1,cpuw,w1)+wpfx+operi(2,cpuw,w6)
        inserts(s,w1,i)
      endif
    else 'LINKAGE FROM PROC LABEL LOCATION
      'w6="|mk 1"+cr+linkadd(wn+sigs,qeax)+wpfx+operi(2,cpuw,w6)+"|mk 0"+cr
      lnks=linkadd(wn+sigs,qeax)+wpfx+operi(2,cpuw,w6)
      w6=""
    endif
    flbl=1 'prevent compaction
    '
  case 5 'AT
    '
    'IN DECLARE STATEMENT
    '
    'EXTERNAL / VECTORED FUNCTION DECLARATION
    '
    'declare function xyz() as sys at a
    '
    '
    if nd<>18
      i=swd : skiplspace(s,i)
      exit do
    endif
    a=ascn
    skiplspace(s,i)
    if ascn=91 'DIRECT VECTOR [EBX+8] etc
      pf=0
      w9=pword(s,i)
    elseif ascn<>64
      w9=NewStatVarStr(0) 'NEW PROCEDURE VECTOR
      pf=0
      inserts(s,w9+"=",i) 'FULL ADDRESS EXPRESSION FOLLOWS
      ascn=64
    else '@ address coupling
      'LINK A FUNCTION TO AN EXISTING VARIABLE OR ANOTHER FUNCTION
      nobr=1
      'i++
      w9=pword(s,i) 'DIRECT COUPLING
      if wpfx
        w9=ow 'USE ORIGINAL NAME
      endif
      nobr=0
      pf=0
    endif
    '
    'itr calling conventions must match
    '
  case 6 'LABEL
    '
    'ADD UNSIGNED LABEL
    flbl=1 ' (also prevents deletion during compaction)
    '
  case 7 'NOSIG
    '
    b=-4 'LOW LEVEL CALL, NO SIGNATURE CHECKING
    flbl=1
    w2="@"
    w5=""
    w9=wn
    '
  end select
  '
  loop
  '
  'MAP  PROCEDURES
  '===============
  '
  ' FUNCTION SUB DECLARE but exclude METHOD
  '
  if nd<>13 'EXCLUDE METHODS nd=13
    '
    'CREATE PROCEDURE RECORD
    ' excluding methods
    '
    c=0
    '
    'IF DECLARED
    '-----------
    '
    if nd=18
      if lby
        '
        'ADD LIBRARY IF NOT SEEN BEFORE, THEN ADD PROC TO LIST
        '
        c=addlib(lby) : lby="" : w9=ali
        atf=1
      else
        if pf
          'NEW PROCEDURE VECTOR
          w9=NewStatVarstr(0)
        endif
      endif
    endif
    '
    '
    '
    if (ccp=3)and(atf>0)
      ccp=2 '64BIT EXTERNAL CALL
    endif
    '
    if w2="@"
      w2="#@" 'NO PARAMS
    elseif w2="@." 'ELLIPSIS
      w2="#@."
    endif
    '
    if w5=""
      if b=-4
        w5="sys"
      else
        w5="," 'NO SPECIFIED RETURN
      endif
    endif
    if dfv=0
      w4=""
    endif
    dfv=0
    if len(w4)>0
      if asc(w4)<>40
        w4="(,"+w4+")" 'DEFAULT PARAMS
      endif
    endif
    '
    '
    'CREATE FULL PROCEDURE RECORD (READ BY NEXTPROC)
    '
    'prototype / returntype callsig/alias  calllib metatype  calling-convention patchoffs namedparams
    'EG: #long#string@01 double foo#long#string 0 FA 0.       (,a=3,b="X",)
    '    #long#string@01 double Foo 0 GA 0.       (,a=3,b="X",)
    '    #long#string@01 double [ebx+0x1000] 0 HA 0.      (,a=3,b="X",)
    '
    'w2 signature including param types and reference levels
    'w4 default params, if any
    'w5 return type
    'w9 callnamesig or alias or vector
    '
    w3=w2+" "+w5+" "+w9+" "+str(c)+" "+chr(65-b)+chr(65+ccp+crgd)+" 0.       "+w4+cr
    funl=instr(w3,"0.")-1 'patch location 'allowed 8 spaces for patchin
    '
    '
    ================================================================
    dct=0 'each declaration
    newrecord wn
    funl+=spj+4      ' patch location
    mrcsi(w3,me,1)   ' list of param signatures (overloadable if -5)
    drc(me).a=b      ' metatype -4 or -5
    mqf=me
    addme()
    if ert
      ret
    endif
    w5=""
    ali=""
    d=0
    e=0
    '
    'DECLARATION
    '
    if nd=18
      dcp=0
    endif
    '
    '
  endif ' nd=11,12,18 but not 13
  '
  end subroutine 'procedurerecord


  ===================
  subroutine ParseDim
  ===================
  '
  'inputs bpb
  '
  dimiter:
  '=======
  '
  do
    '
    'CHECK END OF DIM
    '================
    '
    m=0
    skiplspace(s,i)
    '
    '
    'supports null param ',)'
    if ascn=44
      i++
      nextinstruct(s,i)
    endif
    '
    'CHECK FOR END OF DIM
    '
    if bpb 'CLOSING BRACKET EXPECTED
      if ascn=rbr
        i++
        skiplspace(s,i)
        m=2 : bpb=0
      elseif (iss(ascn)<>0)or(ascn=125)
        nextinstruct(s,i)
        if ascn=rbr
          i++
        endif
        m=2 : bpb=0
      endif
    else 'CLOSING BRACKET NOT EXPECTED
      if (iss(ascn)<>0)or(ascn=125)
        m=2 ':' '}' TO EXIT DIM STATEMENT
      endif
    endif
    '
    if nd<10 'DIMS ONLY
      if wt
        if ws=""
          'type defined but no variables
          m=0 : nextinstruct(s,i) 'LOOK AHEAD FOR VARIABLE NAMES
        endif
      endif
    endif  
    '
    '
    if m=2 'END OF DIM OR DECLARATION
      '
      'LOCAL VARIABLES SETUP INLINE
      '
      '
      'ASSIGN TYPE IF NEEDED
      '
      if ws
        if wt=""
          ert=465 : ers="undefined type for "+ws
          exit subroutine
        endif
      endif
      wr=wt
      dg=2
      goto recovar
    endif 'm=2 'end of dim or declaration
    '
    '
    'NEXT PARAMETER OR TYPE IN THE LIST
    '==================================
    '
    string wrp
    do
      a=asc(wr)
      if isw(a)
        wrp=wr
      endif
      wr=tword(s,i)
      select dic(" * 1, ptr 1, byval 2, byref 3, optional 4, $ 5, % 5, ' 6, ; 6, ... 7, ",wr)
      case 0 : exit do
      case 1 : fdd++        '*
      case 2 : fc=1 : fdd=0 'BYVAL
      case 3 : fc=2 : fdd=1 'BYREF
      case 4 : opa=17       'set optional flag
      case 5 :              'IGNORE $ %
      case 6 : endline(s,i) 'COMMENT
      case 7                '...
        a=ccp
        if (a=0)or(a=8)
          a=1 'AUTO CDECL ELLIPSIS
        endif
        'a or=256
        ccp=a
        sigd+=chr(46)
        goto dimiter 'ELLIPSIS ...
      end select
    loop
    '
    '
    'IDENTIFY TYPE
    '=============
    '
    f=0
    if wr="as" 
      wr=tword(s,i) 'AS TYPE
      f=2
'/*
      if nd>10
        if ascn=61
          w4+=extractvarname(ws)+captsx(s,i)+cm
          skiplspace(s,i)
          'APPEND TYPENAME TO SIGNATURE
          if fc=0
            'fdd+=bref
          endif
          sigs+="#"+wr
          sigd+=chr(fdd+opa+48)
          wt=wr
          dfv=1
          if nd<18
            wva(2)+=wr+" "+ws+cr 'ADD TO LIST FOR LATER INSTANTIATION
          endif
          ws=""
          'print sigd cr ascn cr nd cr bpb
          goto dimnext
        endif 'ascn=61
      endif 'nd>10
'*/
    elseif nd=18 'DECLARED PROCEDURES
      a=i
      b=isptr(s,i)
      '
      if (ascn=44)or(ascn=rbr)
        if typf=0
          if (identype(wr)<>0x10)or(b>0) 'NO VOID but void*
            fdd=b
            f=3 'TYPE WITHOUT PARAM NAME
          endif
        endif
      else 'more words
        if b
          i=a : skiplspace(s,i) 'STEP BACK TO INCLUDE '*'
        endif
      endif
    endif
    '
    ow=wr
    '
    if f
      goto astype
    endif
    '
    'CHECK FOR VARIABLE NAMES
    '
    if nd<10 'VARIABLES
      if typf 'KNOWN TYPE
        if isxn 'no assignments
          gosub AddVarList
          goto dimnext
        endif
      endif
    endif
    '
    if ascn=97
      w1=wordahead(s,i)
      if w1="as"
        if nd>10 'AS PROCEDURE PARAM TYPE
          if fc=0
            fdd+=bref 'IMPLICIT BYREF PARAM
          endif
        endif
        gosub AddVarList 'VARIABLE NAME
        goto dimnext
      elseif w1="at"
        gosub addvarlist 'VARIABLE NAME
        goto dimnext
      endif
    elseif ascn=123 '{
      gosub AddVarList 'MULTIASSIGN {..}
      goto DimNext
    endif
    '
    'EXPLICIT C TYPES
    =================
    '
    if (isa(ascn)<>0)or(ascn=42)
      '
      i=swd 'REPARSE
      a=0
      '
      nobr=1 : wr=mword(s,i) : nobr=0 'MACRO EXPANSION
      '
      if lenw=0
        '
        continue do 'FOR EXIT PROCEDURES
      '
      elseif (mc=-4)or(mc=-9)or(mc=-13)or(mc=-14)
        '
        if nd=18
          a=0
        else
          ers="reserved word" : ert=319 : ret
        endif
        '
      else 'PRIMITIVES UDT / CLASSES
        '
        'a=identype(ow)
        a=identype(wr)
        '
      endif
      '
      if a
        f=1 : typf=a
        goto astype
      endif
      '
    endif 'identify c type
    '
    '
    'IMPLICIT TYPE (PROTOTYPES ONLY)
    ================================
    '
    assieq(s,i)
    '
    a=0
    if nd>10
      select ascn
      case 44,40,41,61,91 ',()=['
      a=1
      end select
    endif
    '
    if a
      '
      if ascn=rbr
        if wr="void"
          continue do 'IGNORE VOID
        endif
      endif
      '
      'skip ()() [] etc
      '
      if (ascn=lbr)or(ascn=91)
        '
        if nd=18
          b=identype(wr)
          if b
            wt=wr : wr="__" : typf=b
          endif
        endif
        '
        if wt="void"
          wt="sys"
        else 'not void
          fdd++ 'ADD INDIRECTION
        endif
        if isostr(typf)
          fdd++ 'EXTRA INDIRECTION FOR STRINGS
        endif
        '
        'DO NOT SWALLOW DISCARD [] ()
        while (ascn=lbr)or(ascn=91)
          capture(s,m,i,0)
          wr+=mid(s,m,i-m)
          skiplspace(s,i)
        wend
       '
        ascw=asc(wr)
        assieq(s,i)
        '
      endif ' (..) [..]
      '
      '
      'C TYPE OR DEFAULT TYPE FOR FUNCTION PARAMS
      '------------------------------------------
      '
      ws=string(fdd,"*")+wr
      '
      'CHECK FOR INFERRED TYPE (BY EXPRESSION)  IN A PROTOTYPE
      '
      typd=typf
      a=0
      select ascn
      case 41 : a=1 ')'
      case 44 : a=1 ','
      case 61 : a=2 '='
        if not wt
          'opa=17 'set optional flag
          wr=dimtype(s,i+1)
          typd=typg
        endif
      end select
      '
      if a
        if wt
          wr=wt 'PRIORITY
        elseif a=2
          'INFERRED
        elseif typd
          wr=typename(typd)
        else 'UNDEFINED
          'ITR #LOOKAHEAD
          'wr="sys" ' 32 / 64 BIT ACCORDING TO MODE
          ert=435 : ers="undefined type: "+wrp
          ret
        endif
        '
        'APPEND TYPENAME TO SIGNATURE
        if fc=0
          if astb
            fdd+=bref
          endif
        endif
        astb=0
        sigs+="#"+wr
        sigd+=chr(fdd+opa+48)
        '
        skiplspace(s,i)
        dg=1 : goto recovar
      endif ' a<>0
    endif 'nd>10
    '
    =======
    astype:
    =======
    '
    if f
      '
      'EXPLICIT TYPE
      '-------------
      '
      a=typf
      '
      if f>=2
        a=identype(wr)
        if f=2
          typf=a 'REMEMBER TYPE FOR FURTHER PARAMS
        endif
        f=2 'CHANGE FROM F=3
      endif
      '
      if a=0
        ers="Unknown type " : ert=201 : ow=wr : ret
      endif
      '
      'POWERBASIC format: AS ASCIIZ*80
      '
      a=0
      if nd<10
        '
        rmuldim:
        ========
        '
        skiplspace(s,i)
        if ascn=42
          a=i
          i++
          skiplspace(s,i)
          if nisxn
            w1=mword(s,i)
          else
            nmb=0
          endif
          if nmb
            wordval(s,a+1,i)
            ws+=left(ws,len(ws)-1)+"["+str(dv)+"],"
            goto rmuldim 'MULTIDIM
          else
            i=a 'revert
          endif  
        endif
      endif
      '
      w3=wr 'type
      b=0 : w5=""
      '
      if ws
        a=isptr(s,i)
        if a
          fdd+=a : b+=a : w5="*"
        endif
      endif 'ws
      '
      if w3="string"
        if nd<>18
          lcl=1 : lcls=1 ' FLAG LOCAL DYNAMIC STRINGS
        endif
      endif
      '
      skiplspace(s,i)
      '
      'ARRAY OF A TYPE
      '
      if ascn=91
        inserts(s,"__",i)
      endif
      '
      if nd>10
        if f=2
          'APPEND TYPENAME TO SIGNATURE
          sigs+="#"+w3
          sigd+=chr(fdd+opa+48)
        endif
      endif
      '
      'itr w5 * / ptr applies to one element only
      '
      if ws=""
        wt=w3+w5
        continue do 'FIRST TIME PREDEF ONLY
      endif
      '
      dg=1
      '
      if wt=""
        wr=w3+w5 'POSTDEF
        if ascn=61
          dg=4
          nwd=i+1
        elseif ascn=97
          if wordahead(s,i)="at"
            dg=3
          endif
        endif
        if dg>=3 'REARRANGE ORDER OF TERMS
          m=i
          i=nwd
          capts(s,i)
          ws=left(ws,len(ws)-1) 'REMOVE END COMMA
          if dg=4
            if iszstra(typf)
              a=asc(ws,len(ws))
              if (a<>41)and(a<>93)
                ws+="[]" 'TO AUTO SIZE CHAR ARRAY
              endif
            endif
          endif
          wt=ws+" "+mid(s,m,i-m)+" as "+wr+" "
          inserts(s,wt,i) 'REPROCESS VARIABLE
          ws="" : wt="" : dg=0
          goto dimnext
        endif 'dg>=3
        '
      else 'WT ALREADY DEFINED
        '
        wr=wt    'PREDEF
        wt=w3    'SET NEXT PREDEF
      endif
    endif 'f=1 IDENTIFIED TYPE f=2 'AS' TYPE 
    '
    '
    recovar: 'DECLARE VAR
    '====================
    '
    '
    'DG=0 NO TYPE YET
    'DG=1 TYPE IDENTIFIED
    'DG=2 END OF DIM STATEMENT
    'DG=3 PREVENT APPENDING VARIABLE NAME TO WS LIST
    '
    if dg 'ALL DG STATES
      '
      'RECORD VARIABLES/PARAMS
      '
      assieq(s,i)
      if ws 'VAR NAMES TO PROCESS
        pn++ 'PARAM COUNTER
        '
        'CHECK FOR ARRAY TYPEs
        '
        if (ascn=91)or(ascn=lbr)
          fdd++ 'add indirection
          if isostr(typf)
            fdd++ 'extra indirection
          endif
          while (ascn=91)or(ascn=lbr)
            'DISCARD
            capture(s,m,i,0)
            skiplspace(s,i)
          wend
        endif
        '
        if nd<10 'VARIABLES AND CONSTANTS
          if cnst
            declvars(wr+" "+w4+cr,nd) 'INSTANTIATE CONST WITH VALUE
            w4=""
          else
            declvars(wr+" "+ws+cr,nd) 'INSTANTIATE VARS
          endif
        else 'nd>10 PROCEDURE PROTOTYPES
          if nd<18
            wva(2)+=wr+" "+ws+cr 'ADD TO LIST FOR LATER INSTANTIATION
          endif
          if cpuw=8
            a=identype(wr)
            if asc(ws)<>42
              if (a=0x6a)
                ers="Cannot pass extended float params byval"
                ert=501           
              endif
              if a>=typh
                if lent>8
                  typq(pn)=lent-8
                endif
              endif
            endif
            typl(pn)=a
          endif 'cpuw=8
        endif 'nd
        '
        if ert
          exit subroutine
        endif
        '
        skiplspace(s,i)
        assieq(s,i)
        '
        if (ascn=60)or(ascn=61)or(ascn=123)or(nd>10)
          wr=ws : ws="" 
          dg=3
          gosub addvarlist
          'goto Dimnext
        endif
        ws=""
      endif 'len ws
      '
      if f=1
        if (ascn=60)or(ascn=61)or(ascn=123)
          wr=wv
          'DIM A AS FLOAT=1.618
          gosub addvarlist
          goto DimNext
        endif
      endif
      '
      if dg=2 'END OF DIM
        '
        'INITIALIZATION
        '
        'includes stack allocation and zero and explicit vales
        '
        if nd<10 'VARIABLES
          '
          if w4
            'hiex+=w4 : rps=1 'APPEND EXPLICIT ASSIGNMENTS
            if nd=3 'STATIC VARS
              w4="|mk 1"+cr+w4+"|mk 0"+cr
            endif
            inserts(s,w4,i)
          endif
          w1=""
          '
        else 'nd>10 'PROTOTYPES
          '
          ws=""  'FURTHER PROCESSING FOR PROCEDURES
          '
        endif 'nd
        '
        exit subroutine
        '
      endif 'dg=2
      dg=0
      goto dimnext 'NEXT ITEM IN DIM STATEMENT
    endif 'dg
    gosub AddVarList
    '
    dimnext:
    '=======
    '
    skiplspace(s,i)
    '
    if (ascn=44)or(ascn=125)or(ascn=41)
      fdd=0 : fc=0 'CLEAR INDIRECTION FLAGS
    endif
    '
  loop ' NEXT DIM MEMBER
  '=====================
  '
  end subroutine 'ParseDim


  subroutine AddVarList 'ADD VARIABLE TO LIST
  '==========================================
    '
    'output wr w2
    '
    w2="" 'at ..
    w3="" 'possible array
    c=0   'flag empty brackets
    e=0   'elct+1 holder
    '
    '
    skiplspace(s,i)
    '
    'CAPTURE ARRAY SUPPORTING MULTIPLE [][].. 
    '=============
    '
    while (ascn=lbr)or(ascn=91) '( [
      '
      'CHECK FOR EMPTY BRACKETS
      '
      c=-1 'ARRAY PRESENT
      '
      w1=wordahead(s,i+1)
      a=asc(w1)
      if (a=rbr)or(a=93)
        i=nwd 
        c=1 'SIGNAL EMPTY BRACKETS
      else
        elct=0
        capture(s,m,i,a)
        e=elct+1 'tally elements
        w3+=mid(s,m,i-m)
      endif
      skiplspace(s,i)
    wend
    '
    '
    'AT POINTER
    '==========
    '
    if ascn=97
      if wordahead(s,i)="at"
        m=i
        i=nwd
        '
        'SUPPORT DIRECT COUPLING OF VARIABLES BY ADDRESS
        'ALSO REGISTERS .. at @ecx  at @rcx
        '
        'SUPPORT COUPLING OF 'AT' VARIABLE
        '
        'CAPTURE OPERAND IN SQUARE BRACKETS
        if asc(wordahead(s,i))=91
          a=instr(nwd,s,"]")
          if a
            nwd=a+1
            skiplspace(s,nwd)
          endif
        endif
        '
        a=asc(s,nwd)
        a=isx(a)
        '
        if a=0
          b=nwd
          if wordahead(s,b)="as"
            a=2
          endif
          nwd=b
        endif
        if a=0            'AN EXPRESSION FOLLOWS
          wr="*"+wr       'SPECIFY BYREF
          mid(s,m)="= "   'REPLACING 'at'
          i=m
          ascn=61
        else 'a<>0 'linkage/coupling to another variable or address
          i=nwd
          w2=" "+mid(s,m,i-m)
        endif
        skiplspace(s,i)
      endif 'at
    endif
    '
    'outputs w4 ws
    '
    'assigdim:
    'simple assignment: =
    'AND
    'multiassignment: <=' '=>' '={...}' '<={...} '=>{...}'
    '
    m=0
    if (ascn=60)or(ascn=61)or(ascn=123)
      m=ascn
      b=i
      a=i+1 'next char
      '
      if m=60 '<=
        a++
      elseif m=123 '{
        a--
      endif
      '
      skipspace(s,a)
      '
      '
      'CHECK FOR ARRAY DATA
      '
      if (c=1)or(isq(ascn)<>0) '[] () "abc"
        '
        'ONLY SUPPORTS ONE STRING LITERAL
        '
        if (iszstra(typf)<>0)and(w3="") 'CHAR
          c=-2 'array status
          w1=tword(s,a)
          w3="["+str(lenw)+"]" 'INSERT ARRAY 'INCLUDES 2 END NULLS
        endif
      endif
      '
      'CAPTURE EXPRESSION
      '
      i=a
      nextinstruct(s,i)
      elct=0
      capts(s,i) '{,,} tally elements by comma
      if elct 'tally by outer commas
        if e=0 '] 'not already indexed
          if c>=0 '[] or () or none
            w3+="["+str(elct+ixb)+"]" 'insert array size
          endif
        endif
      endif
      '
      'IF EXPRESSION EXISTS
      '
      if i>a
        w1=wr
        w2=""
        '
        'new e usage for ptr count
        'int i1=1
        'e=isptr(w1,i1)
        e=1
        while asc(w1,e)=42
          e++
        wend
        '
        if (nd<10)and(cpoint=0)and((e>1)or(fdd>0)or(indt>0))
          'ASSIGN POINTER VALUE BUT NOT IN PROTOTYPES (n>10)
          if indt
            w2="@@"
          else
            w2="@"
          endif
        endif
        '
        if m=123
          w9="=" '={..}
        else
          w9=""
        endif
        w1=w2+extractvarname(w1)+w9+mid(s,b,i-b)
        '
        if nd<10
          w4+=w1+cr
        else 'ND>10, PARAMS DEFAULTS
          dfv=1
          w4+=w1+cm
        endif
        w1=""
        w2=""
      endif 'i>a
      '
    else 'NO EXPLICIT ASSIGN
      '
      a=1
      if ascn=97
        if wordahead(s,i)="as"
          a=0 'DO LATER
        endif
      endif
      if (nd>10)and(a<>0)
        'OPTIONAL DEFAULT PARAMS
        if opa=17
          w9="=null,"
        else
          w9="=.,"
        endif
        w4+=extractvarname(wr)+w9 'IMPLICIT ASSIGNMENT
      endif 'nd
    endif
    '
    '
    'APPEND VARIABLE NAME (AND ARRAY) TO VARIABLE LIST
    'exclude PostDef Params F(N=V AS XXXX, ...)
    '
    if dg<>3
      wv=wr
      if ise(ascn)=0
        w2+=cm
      endif
      ws+=string(fdd,"*")+wv+w3+w2
    endif 'dg<>3
    dg=0
  end subroutine 'AddVarList


  subroutine iterations
  =====================
  '
  '
  ' ####   ####   #####
  ' #     #    #  #    #
  ' ####  #    #  #####
  ' #     #    #  #    #
  ' #      ####   #    #
  '
  '
  forb=""
  fore=""
  fors=""
  nwe=""
  nws=""
  w1=""
  typr=4
  cnd=0
  e=0
  if ascn=lbr
    i++ : e=1 : skiplspace(s,i) 'SKIP LEFT BRACKET
  endif
  a=i
  forb=captsx(s,i)
  if (ascn=44)or(ascn=59)
    fro=2
    typr=4
    jmp fwd itlim
  endif
  '
  i=a
  wr=pword(s,i)
  '
  if mp=0
    'create it as sys variable
    if relaxed
      varsal("sys "+wr)
      if ert
        exit subroutine
      endif
      wr=mrcso(qme,1)
      typ=cpuw
    else
      ers="Iteratator must be defined " : ert=400 : ret
    endif
  endif
  '
  typr=typ
  '
  'SKIP EQUALS SIGN
  '
  skiplspace(s,i)
  '
  if ascn=61
    i++
  else
    ers="Missing '='" : ert=502 : ret
  endif
  '
  nobr=123 : forb=captsx(s,i)
  w6=owa 'ITERATOR
  '
  ======
  itlim: 'SET LIMIT VALUE FOR ITERATOR W4
  ======
  '
  w5=tword(s,i) 'TO' or ';'
  '
  if w5="to"
    '
  elseif (ascw=44)or(ascw=59)
    fro=2
    if (ascn=44)or(ascn=59)
      w5="" 'NO LIMIT EXPRESSION SPECIFIED
      jmp fwd itstep
    endif
  else
    ers="missing 'to' or ';' " : ert=513
    ret
  endif
  '
  nobr=123 : fore=captsx(s,i)
  w5=""
  a=1
  w3=tword(fore,a)
  if instr("<>=",w3)
    'INSERT ITERATOR FOR <E ETC
    b=a : a=swd
    identop(fore,a,b)
    w3=w6
    w8=mid(fore,a,b-a)
    w9=w8
    w5=w3+fore
    fore=mid(fore,b)
  elseif instr("<>=",chr(asc(fore,a)))
    'I<E ETC
    b=a+1 
    identop(fore,a,b)
    w8=mid(fore,a,b-a)
    w9=w8
    w5=fore
    fore=mid(fore,b)
  else
    w3=w6
    w5=fore
    w8="<="
    w9=">="
  endif
  '
  =======
  itstep: 'CHECK FOR STEPPER EXPRESSION W2
  =======
  '
  'PRESUME INCREMENT
  '
  a=0 : c=0
  skiplspace(s,i)
  '
  if (ascn=44)or(ascn=59)
    i++ : skiplspace(s,i) ' COMMA OR SEMICOLON SEPARATORS
    w2=""
    if isa(ascn)
      a=3
    else
      a=5
    endif
  elseif ascn=0x73 's
    w7=wordahead(s,i)
    if w7="step" 'STEP ...
      i=nwd
      a=1
    endif
  endif
  '
  if a=5
    '
  else
    nobr=123 : fors=captsx(s,i)
  endif
  '
  if a
    w2=fors 'STEP EXPRESSION W2
    if a=3 'I+=N 'C STYLE STEP
      c=1
    endif
  endif 'END STEPPER
  '
  skiplspace(s,i)
  '
  if e
    if ascn=rbr
      i++ 'SKIP RIGHT BRACKET
      skiplspace(s,i)
      if ascn<>123
        if nisxn
          string w10=captsr(s,i)+cr+"next"+cr
          if ascn=58 or ascn=59 then i++
          inserts(s,w10,i) : w10=""
        endif
      endif
    endif
  endif
  '
  '
-------------------------------
if fro=1 'basic-style iterator
===============================
'
w4=typename(typr)
nwe=newtmpvar(w4)
'
-------------------
if fors 'step given
-------------------
'
nws=newtmpvar(w4)
'
w1=nws+"="+fors+"
._for``
if "+nws+">0
  if not "+w3+w8+nwe+"
    jmp fwd _end_for``
  endif
else
  if not "+w3+w9+nwe+"
    jmp fwd _end_for``
  endif
endif
"
w2=w6+"+="+nws 'generic tepper
'
----------------------------
else 'fors="" 'no step given
----------------------------
w1="
._for``
if not "w6+w8+nwe+"
  jmp fwd _end_for``
endif
"
w2=w6+"++" 'most common stepper
'
------------------
endif 'fors 'steps
------------------
'
w1=w6+"="+forb+cr+nwe+"="+fore+cr+w1
'
w2="._step``
 "+w2+"
 jmp _for``
._end_for``
"
w5=""
'
--------------------
else 'fro=2 'c-style
--------------------
'
w1=forb+"
._for``
"
w2="._step``
 "+fors+"
 jmp _for``
._end_for``
"
if w5
  'APPEND COMPARE AND JUMP
  w1+="if not "+w5+"
 jmp fwd  _end_for``
 endif
"
endif
'
---------------------------------
endif 'fro basic/C style iterator
---------------------------------
  '
  w4=str(nsls(4))
  replace(w1,"``",w4)
  replace(w2,"``",w4)
  '
  nxs(nx)=w2 : nx++ 'STORE STEPPER EXPRESSION
  '
  '
  'print w1 cr cr w2
  '
  'CHECK AHEAD FOR {
  '
  a=cbrencah(s,i,4)
  '
  if fro=2 'POSSIBLE C EXPRESSION. NEED BODY BRACES?
    if a=0
      b=0
      c=i
      do
        icas=1 : ilc=1 : w2=bword(s,i)
        if lenw=0
          exit do
        endif
        if ascw=59
          a=swd : exit do ';' c separator
        endif
        b++
        if b>16 'words limit
          exit do
        endif
      loop
      if a
        w2="{"+mid(s,c,a-c+1)+"}"
        i=a+1
        inserts(s,w2,i)
        cbrencah(s,i,4)
      else
        i=c 'restore position
      endif
    endif
  endif
  '
  inserts(s,w1,i)
  fro=0 : nobr=0
  w1="" : w2="" : w3="" : w4="" : w5=""
  w6="" : w7="" : w8="" : w9=""
  '
  end subroutine 'iterations



  ===================================================
  subroutine makeheaders '(string*wr,*w4,*w3, int mo)
  ===================================================
  '
  '  mo=1: #LOOKAHEAD TO BUILD FORWARD DECLARATIONS
  '  mo=2: SCAN THROUGH COMBI CLASS BLOCK TO BUILD CLASS AND METHODS BLOCKS 
  '
  '  wr holds code block and returns main body section
  '  w3 returns defined function / method code
  '  w4 returns virtual / static body section
  '  w5 holds the class name
  '
  int a,b,c,d,e,f,i,m,idtp,stw,lns
  string s,w1,w2
  w1="" : w2=""
  i=1 : s=wr : w3="" : w4="" : e=i
  '
  do
    if mo=1
      nextinstruct(s,i)
    else
      skiplspace(s,i)
    endif
    a=0
    if ascn<=13
      a=1
    elseif ascn=58
      a=1
      i++
    endif
    '
    w1=tword(s,i)
    if lenw=0
      exit do
    endif
    if a
      e=swd
    endif
    if mo=1
      if ascw=rbr
        exit do 'INSIDE A SCOPE
      endif
    endif
    '
    'COMMENTS
    '
    if isc(ascw)
      d=swd : e=swd : endline(s,i)
      if ascn=95 'lnm
        lns=d 'prior line number position
      endif
      i+=2
      continue do
    endif
    '
    '
    'SKIP QUALIFIER WORDS
    '
    'if mo=1
    '  if idword(" leaf ",w1)
    '    w1=tword(s,i)
    '  endif
    'endif
    '
    'if w1="virtual"
    '  midspace(s,swd,swd+7) : vt=1
    '  continue do
    'endif


    idtp=0
    mp=lookupm(w1)
    if mp
      b=drc(mp).a
      idtp=identype(w1)
    endif
    '
    if mo=2
      '
      if ascw=47
        if ascn=92 '/\
          w3="" : w4="" : exit subroutine  'RESTORE ORIGINAL : (SEPARATE METHODS BLOCK OR EXTERNAL)
        endif
      endif
      '
      if ascn=61
        goto classign
      endif
      '
      '
      'INHERIT OR MACRO EXPANSION
      '--------------------------
      '
      a=0
      if idtp>=typh
        if ascn<>42
          f=idtp-typh
          w2=mrcso(f,1)
          if instr(w2,cr+"/\"+cr)
            a=1
          endif
        endif
      elseif idword(" of from has incl ",w1) 'members removed
        w1=tword(s,i)
        a=expandm(w1)
        if a
          s=left(s,swd-1)+w1+mid(s,i)
          i=swd
          wm=s
          continue do
        endif
        a=1
        i=swd
      endif
      '
      if a
        '
        'CAPTURE IN TOP SECTION (FOR LATER SPLITTING INTO VIRTUAL AND BODY)
        '
        endline(s,i) : i+=2
        w4+=mid(s,e,i-e)
        midspace(s,e,i) 'blankout
        e=i
        continue do
      endif
      '
      '
      a=ascn
      '
      if ise(a)
        m=i
        nextinstruct(s,m) : a=asc(s,m)
        if a=123
          i=m
        endif
        skiplspace(s,i)
      endif
      '
      'NESTED TYPE
      '
      if a=123
        c=swd : capture(s,i,i,m) : skiplspace(s,i)
        stw=0
        e=i : continue do
      endif
    endif 'mo=2
    '
    '
    'BODY ELEMENTS?
    '
    '
    if w1="#byref"
      bref=1
    endif
    if w1="#byval"
      bref=0
    endif
    '
    'EXCISE FLAGS
    '------------
    '
    if w1="packed"
      w1=tword(s,i) ' follow on for type typdef class
    endif
    '
    if w1="static"
      stw=1
      midspace(s,e,i)
      continue do
    endif
    '
    'EXCISE BODY BLOCKS
    '------------------
    '
    'except UNION STRUCT #DEFINE
    '
    if idword(" internal subroutine ",w1)
      capturedefs(s,i,w1)

      if mo=2
        w3+=mid(s,e,i-e)+cr
        midspace(s,e,i)
      endif
      stw=0
      e=i : continue do
    endif
    '
    if idword(" % $ type class macro def deff typedef enum ",w1)
      a=0
      if ascw=36 '$
        a=1
      elseif ascw=37 '%
        a=1
      endif
      w2=tword(s,i)
      if a=0
        if nisxn
          if ascn<>123
            if ascn<>40
              'single liners
              'beware def x (%1)
              a=1
            endif
          endif
        endif
      endif
      '
      if a
        endline(s,i) 'SINGLE LINER
      else 'a=0 assume block
        capturedefs(s,i,w1)
      endif
      if mo=2
        defbuf+=mid(s,e,i-e)+cr
        undefbuf+="undef "+w2+cr
        midspace(s,e,i)
      endif
      stw=0
      e=i : continue do
    endif
    '
    'EXCISE DECLARATIVES ETC
    '-----------------------
    '
    '
    a=idword(" #def #define ### #view #endv var #byref 1, #byval indexbase #indexbase ",w1)

    if mo=1
      if a=0
        a=idword(" ! declare #declare ",w1)
      endif
      if a
        'SKIP LINES ENDING IN  , _ \
        endcontline(s,i)
        endline(s,i)
        e=i+2
        stw=0
        continue do
      endif
    endif
    '
    '
    '========
    classign:
    '========
    '
    if ascn=61
      a=1 'ASSIGNMENTS itr array assignments
    endif
    '
    if a
      'SKIP LINES ENDING IN  , _ \
      endcontline(s,i)
      endline(s,i)
      i+=2
      if mo=2
        w3+=mid(s,e,i-e)'capture for methods block
        midspace(s,e,i) 'blank
      endif
      e=i
      continue do
    endif
    '
    'LOOKAHEAD FOR METHOD/FUNCTION/PROCEDURE BODY
    '--------------------------------------------
    '
    a=0
    '
    if idtp 'IDENTIFIED TYPE
      f=swd
      isptr(s,i)
      w1=tword(s,i)
      if isc(ascw)
        endline(s,i) : midspace(s,swd,i) 'blank out comment
      elseif ascn=lbr
        if mo=2
          a=3 'TREAT AS C METHOD
        else 'mo=1
          a=10 'TREAT AS C STYLE FUNCTION
        endif
        swd=f
        i=swd
      else
        endline(s,i) 'NOT DECLARATION OF PROCEDURE
      endif
    elseif ascn=lbr
      'NOT A PROTOTYPE
      capture(s,i,i,m)
      skiplspace(s,i)
    else 'COULD BE A PROTOTYPE
      int aa,ab,an,aw
      aa=0
      if mo=2
        ab=swd
        aw=ascw
        an=ascn                           
        aa=idword(" ! declare #declare ",w1)
        if aa
          midspace(s,swd,i)
          aa=i 'hold position
          w1=tword(s,i) 'what is next
        endif
      endif
      '
      readfun:
      ========
      '
      a=dic(" function 1, procedure 1, sub 2, method 3, static 8,",w1)
      if a=0
        if aa 'an explicit declaration
          a=1
          'revert
          i=aa
          swd=ab
          ascw=aw
          ascn=an
          mid(s,swd)="!"
        end if
      endif
      if a=8
        w1=tword(s,i)
        stw=1 'static
        goto readfun
      endif
      if a
        select ascn
          case 61,43,45,47 : a=0 'function= + etc
          case 42 : if ascw<>33 then a=0 : stw=0
        end select
      endif
      if a=2
        if issub(s,i)=0
          a=0 : stw=0 'EXCLUDE ASM SUB
        endif
      endif
    endif
    '
    if a=0  'NOT A PROCEDURE
      if stw 'STATIC DIM
        endcontline(s,i)
        endline(s,i)
        i+=2
        if mo=2
          w3+="static "+mid(s,e,i-e)
          midspace(s,e,i)
        endif
        stw=0
      endif
    else  'IS A PROCEDURE
      '
      if lns
        c=lns
      else
       c=swd
      endif
      f=i
      '
      if mo=1
        e=c
      endif
      '
      CaptHead(s,i)
      if aa 'explicitly declared
        d=0
      else
        CaptBody(s,i,d,mo)
      endif
      '
      w1=mid(s,e,i-e) 'PROTOTYPE ONLY
      '	
      if mo=1 'BUILDING FORWARD DECLARATIONS
        if (a<=2)
          w4+="! "+w1+cr 'BASIC DECLARATION
        elseif a=10
          w4+=w1+cr      'C DECLARATION
        endif
        if d
          i=d
        endif
      endif
      '
      if (mo=2)
        if a<=3
          if stw=0
            w4+=w1+cr 'STATIC PROCEDURES EXCLUDED
          else 'stw=1
            defpro+="static "
          endif
        endif
        if d=0
          midspace(s,e,i) 'CLEAR PROC HEADER SPACE
        else 'd>0 PROC BODY DETECTED
          w3+=defpro+mid(s,c,d-c)+undefpro+cr  'CAPTURE WHOLE PROC EXCLUDING QUALIFIERS
          defpro="" : undefpro=""
          midspace(s,e,d)   'CLEAR WHOLE PROC AND QUALIFIERS
          i=d
        endif 'd
      endif 'mo=2
      stw=0 'STATIC
      e=i   'UPDATE POSITION FOR NEXT ITEMS
    endif 'a PROCEDURES
  loop
  '
  '
  'STRIP LEADING SPACES AND EMPTY LINES
  if mo>1
    wr=s
    s=""
    'linesltrim(wr) 'PROPERTY LIST
    'linesltrim(w3) 'METHODS BLOCK
    'linesltrim(w4) 'METHOD LIST
  endif
  '
  end subroutine 'MakeHeaders



  ====================================================
  'MakeTypes(unip,atx,ttc,tuc) 'RESOLVE TYPE STRUCTURE
  ====================================================
  '
  'drc:
  '=====================================
  'm0 name
  'm1 structure
  'm2 default values list
  'm3 virtual table maker script
  '=====================================
  'drc:
  '=====================================
  'a  metatype (-3)
  'b  object length
  'c  index of methods table, if present
  'd  flag to indicate virtual table field present
  'e  number of virtual table entries
  'f  max primitive size
  '=====================================

  subroutine MakeTypes

  int a=0,b=0,c=0,d=0,e=0,f=0,g=0,k=0,m=0,n=0,v=0,w=0

  int ctbl=0,vof=0,vtl=0,sih=0,pof=0,pv=0,na=0,wmn=0,wmx=0,wri=0,mth=0,priv=0,
      uni=0,cmo=0,indi=0,sni=0,clas=0,tv=0,x=0,vtlf=0,mps=0,nentry=0

  string w1="",w2="",w3="",w4="",w5="",wd="",wm="",wn="",wr="",ws="",wt="",buil="",
         wih="",tbls="",wpr="",nesn="",ty="",mlist="",vlist="",wrb=""

    drc(me).a=-3 'METATYPE TYPE OR CLASS

    wm=mrcso(me,1)
    k=1
    ttc=0 : tuc=0
    vtl=instr(wm,"/\"+cr) : vtlf=vtl
    buil=""
    if vtl
      'a=drc(me).c and 2
      a=atx and 2
      if a=0
        ctbl=1 'VIRTUAL TABLE IS PRESENT
      endif
    endif
    '
    cmo=unip and 8   'C MODE FLAG
    clas=unip and 16 'class flag
    '
    'CHECK FOR UNION (1) OR TYPE (0)
    '-------------------------------
    '
    a=unip and 1
    unif(uni)=a
    unim(uni)=a
    '
    addme()
    'priv=0x39
    'pp=priv
    '
    '=======================
    do 'FOR EACH MAIN MEMBER
    '=======================
      '
      maindec:
      '
      'SKIP COMMAS
      'SKIP 'HAS' etc
      '
      'READ QUALIFIER WORDS
      '--------------------
      '
      do
        wr=tword(wm,k)
        if lenw=0
          exit do
        endif
        if ascw=59
          continue do
        endif
        '
        if isc(ascw)
          'CAPTURE METACOMMENTS '!...
          a=ascn
          b=asc(wm,swd+2)
          endline(wm,k)
          swd+=2
          w1=mid(wm,swd,k-swd)
          if (a=95)and(b=34)
            cfile=w1
          elseif a=95 'lnm
            lnmks=w1
          endif
          midspace(wm,swd-2,k)
          continue do
        endif
        '
        if wr="virtual"
          continue do 'IGNORE
        endif
        '
        'SUPPORT MACROS INSIDE TYPES
        '
        a=lookupm(wr)
        if a
          m=drc(a).a
          if (m=-18)or(m=-20)
            if ascn=97
              if wordahead(wm,k)="as"
                goto nmacrow 'exclude 'varname as type'
              endif
            endif
            k=swd
            wr=mword(wm,k)
            inserts(wm,wr+" ",k)
            continue do
          endif
        endif
        '
        nmacrow:
        '
        if ascw=35
          '
          'EXTRACT ANY #DEFINES
          '--------------------
          '
          if idword(" #if #ifdef #ifndef #else #endif ",wr)
            md=drc(a).f
            b=k
            k=swd
            w1=left(wm,swd-1)
            metaco(wm,b)
            wm=w1+mid(wm,b)
            if ert
              exit subroutine
            endif
            continue do
          endif
          if wr="#define"
            do
              m=swd
              endline(wm,k)
              k+=2 'include cr
              w1=rtrim(mid(wm,m,k-m))
              definbuf+=w1
              if asc(w1,len(w1))<>92
                exit do  'checking for line continuation '\'
              endif
            loop
          endif
          continue do 'main loop
        endif
        '
        b=dic(" has 1, of 2, from 2, extends 2, align 3, dim 4, as 4, const 4, public 4, protected 4, private 4, ",wr)
        select b
        case 0
          exit do
        case 1
          sih=0
        case 2
          sih=1
        case 3 
          b=swd : wr=tword(wm,k) : v=-val(wr) : a=w and v 
          if a<w
            w=a-v
          endif
        case 4
          'ignore
        end select
      loop
      '
      a=ascw
      '
      'OVERRIDE PREVIOUS ELEMENTS OF SAME NAME
      '---------------------------------------
      '
      'override methods by appending new methods
      '
      '---------------------
      'CHECK FOR END OF BODY
      '=====================
      '
      if lenw=0
        exit do 'END OF STRUCTURE
      endif
      '
      '------------------------
      'CHECK FOR METASTATEMENTS
      '========================
      '
      if a=35
        c=swd : wr=mword(wr,1) : swd=c
        if mc=-13
          md=drc(mp).f
          if md>=100
            metaco(wm,k)
            continue do
          endif
        endif
      endif
      '
      '--------------------------
      'END OF VIRTUAL FUNCTIONS /
      '==========================
      '
      if a=47
        '
        if vtl=0
          continue do 'IGNORE ALL BUT THE FIRST '/' ENCOUNTERED
        endif
        '
        k++ : skiplspace(wm,k) ' /\
        appe(wrb,wri,"/\"+cr)
        '
        drc(qme).e=w/cpuw 'NUMBER OF TABLE ENTRIES
        w=0 : wmx=0 : pof=0 : vof=0 : vtl=0 'CLEAR OFFSETS ETC
        '
        if ascn=0
          wm+=cr              'ensure ending with cr for proper line ending
        endif
        k+=2                  'skip cr following
        '
        'IS A VIRTUAL TABLE POINTER NEEDED?
        '----------------------------------
        '                   
        if (atx>0)
          '
          'INSERT BASE VTP PLACE
          w2=rmk+"___ 0 0 0 0 9AA , int"+cr
          appe(wrb,wri,w2)
          w=cpuw : pof=w : vof=w
          '
        endif
        '
        'INHERITED BODY LIST
        '-------------------
        '
        'insert the accumulated subelements
        '
        if wih 'PASS 2 TO PROCESS INHERITED BODIES
          ws=wih : wih="" : wd=","
          '
          'SPLIT THE STRUCTURE STRING
          '
          wt=mid(wm,k)
          wm=""
          k=1
          '
          goto insert_subelements
          '
        else
          continue do
        endif
        '
      endif 'end of virtual functions /
      '
      '
      '---------------------------
      'UNIONS AND INNER STRUCTURES
      '===========================
      '
      if unif(uni)
        '
        'CHECK WITHIN UNION
        '------------------
        '
        if unim(uni)
          if w>wmx
            wmx=w ' MAX VAR OFFSET+SIZE
          endif
          w=unio(uni)         'RESTORE OFFSET
        endif
        '
        '
        'CHECK END OF UNION/STRUCT
        '-------------------------
        '
        b=swd
        if unif(uni)=1
          if wr="end"
            wah=wordahead(wm,k)
            if idword(" union struct ",wah)
              k=nwd : unif(uni)=a
            endif
          endif
        endif
        '
        ' ) } OR END OF UNION/STRUCT
        '---------------------------
        '
        if a=unif(uni)
          '
          if unim(uni)
            if w<wmx
              w=wmx 'MAX VAR OFFSET+SIZE  IN UNION
            endif
          endif
          '
          'WORDS FOLLOWING STRUC/UNION
          '
          w1=""
          do
            if ascn=59
              k++ : skiplspace(wm,k) : exit do ';'
            endif
            if ise(ascn)
              exit do
            else
              w1=tword(wm,k)
            endif
          loop
          '
          uni--
          midspace(wm,b,k) 'WIPE ENDING
          continue do
        endif
        '
      endif
      '
      'CHECK FOR START OF NESTED UNION / STRUCT
      '----------------------------------------
      '
      d=dic(" struct 1, union 2, type 1,",wr)
      '
      if d
        m=swd
        c=lenw
        uni++         ' stack index
        unio(uni)=w   ' base offset
        unif(uni)=1   ' flag
        unim(uni)=d-1 ' type or union
        unin(uni)=""  ' name
        b=swd
        if isxn
          a=k
          nextinstruct(wm,k)
          if (ascn<>lbr)and(ascn<>123)
            k=a
            skiplspace(wm,k)
            endline(wm,k)
            goto nuname 'brackets not used here
          endif
        endif
        if (ascn=lbr)or(ascn=123)
          'ANONYMOUS
        else
          wr=tword(wm,k)
          'IS THIS STRUCT ALREADY DEFINED?
          if (ascn<>lbr)and(ascn<>123)
            a=identype(wr)
            if a
              midspace(wm,m,m+c) 'blank "struct"
              k=m+c
              uni--
              continue do
            endif
          endif
          unin(uni)=wr+"."
          nextinstruct(wm,k) 'NAME GIVEN
        endif
        '
        '------
        nuname:
        '------
        '
        d=1
        c=k
        '
        if ascn=lbr
          d=rbr : k++ '()
        endif
        if ascn=123
          d=125 : k++ '{}
        endif
        unif(uni)=d
        '
        'CHECK FOR ASSOCIATED STRUC NAME
        '
        if d>1
          capture(wm,m,c,0) : skiplspace(wm,c)
        endif
        midspace(wm,b,k) 'WIPE STRUCT NAME
        if ise(ascn)=0
          if ascn=42
            k++
            mid(wm,b)="sys "+tword(wm,k)
            midspace(wm,c,k)
            ' allocate space for pointer only
            k=b
            uni--
          else
            unin(uni)=tword(wm,c)+"." 'capture 1st associated name
          endif
        endif
        '
        continue do
        '
      elseif a=61 '=' DEMARKATE UNION GROUPS
        '
        if w>wmx
          wmx=w 'SET UNION MAX SIZE
        endif
        w=wmn 'RESET OFFSET
        continue do
        '
      elseif a=43 '+' DEMARKATE UNION GROUPS
        '
        mid(wm,swd)=" " 'WIPE CODE
        if isn(ascn)
          wr=tword(wm,k)
          wmx=val(wr) 'SET OFFSET
        endif
        if w>wmx
          wmx=w 'SET UNION MAX SIZE
        endif
        wmn=wmx 'NEW BASE OFFSET
        w=wmn 'NEW OFFSET
        continue do
        '
      endif 'UNIONS AND INNER STRUCTURES
      '
      '============
      nstructunion:
      '============
      '
      '
      '================================
      'TRANSFORM BASIC SYNTAX TO OXYGEN
      'REARRANGE ELEMENT DECLARATION:
      '================================
      '
      'OVERVIEW:
      '=========
      '
      'C STYLE
      '
      '---------------------------------------------------------------
      ' TYPE/RETURN | NAME | ARRAY OR METHOD/FUNCTION/SUB | (PARAMS) | 
      '===============================================================
      '
      '
      'BASIC
      '
      '-------------------------------------------------------------------
      ' NAME AS | TYPE OR METHOD/FUNCTION/SUB | (PARAMS) | AS RETURN_TYPE |
      '===================================================================
      '
      'TO:
      '===
      '
      '----------------------------------------------------------
      ' TYPE | NAME | METHOD_FLAG: ! | (PARAMS) | AS RETURN_TYPE |
      '==========================================================
      '
      '
      b=swd : n=0 : ascw=0 : indi=0
      a=k
      w1=tword(wm,k)
      k=a
      w2=""
      w3=""
      a=asc(w1)
      '
      'NESTED VARIABLES (NAME DOT)
      '
      if a=123
        w2=rmk+nesn+wr+" "+str(w)+" 0 0 0 0 0AA"+cr
        nesn+=wr+"."
        k++
        appe(wrb,wri,w2)
        continue do
      endif
      '
      if asc(wr)=125
        a=len(nesn)-1
        do
          a--
          if a<=1
            nesn="" : exit do
          endif
          if asc(nesn,a)=46
            nesn=left(nesn,a) : exit do
          endif
        loop
        mid(wm,swd)=" " : continue do
      endif
      '
      'SUB FUNCTION METHOD name ..
      '===========================
      '
      coco=ccx
      crgd=crg
      if coco=0
        if cpuw=8
          coco=2 'MS64
        endif
      endif
      cco=coco
      if (coco=2)and(atx=0)
        coco=3
      endif
      '
      mth=dic(" ! 3, sub 1, function 2, procedure 2, method 3, ",wr)
      '
      if mth
        a=len(w1)
        k+=a
        midspace(wm,swd,swd+a) 'BLANK
        w2=w1 'POSSIBLE NAME
        n=0x11f
        wr="sys"
        a=k 'HOLDING POSITION FOR LOOKAHEAD
        w1=tword(wm,k)
        do
          if not callingconv(wm,k,w1)
            exit do
          endif
        loop
        '
        if ascw=lbr
          k=a : goto pparams
        else
          w3="" ' no '()'
        endif
        '
        'CHECK FOR RETURN TYPE
        '---------------------
        '
        if w1="as"
          a=1 : goto astype
        else
          k=a 'backtrack
          ascw=0
          skiplspace(wm,k)
          goto reagg 'NO RETURN TYPE
        endif
        '
      endif 'PROCEDURES
      '
      w2=wr 'POSSIBLE NAME
      '
      'DECLARE name AS TYPE
      '--------------------
      '
      if w1="as"
        k=nwd : n=1 : a=1 : goto astype
      endif
      '
      '
      a=0
      if nisxn
        m=idword(" signed unsigned short long ",wr) 'TYPE MODIFIERS
        if m
          ctype(wm,k,wr)
          a=typ
        else
          a=identype(wr)
        endif
        '
        'COMPOUND OR CUSTOM TYPE
        '
        if a>=typh
          m=drc(a-typh).a
          '
          'FUNCTION TYPES
          '
          if m=-5
            if nisxn
              wr=tword(wm,k)
            endif
            'itr overload matching
            string wt1
            nextproc(a-typh,wt1,0)
            if (sig="#@")or(sig="")
              sig=","
            endif
            'if priv=0
            '  priv=0x39
            'endif
            '
            'ENCODE PROCEDURE
            '
            wpr=rmk+wr+" "+str(cpuw)+" "+str(w)+" 0       8 "+chr(cco+crgd+65)+chr(atx+65)+" "+sig+" "+sog
            appe(wrb,wri,wpr+cr)
            w+=cpuw
            wpr=""
            continue do
          endif
        endif
      endif 'nisxn
      '
      '
      '=========
      typebfna: 'TYPE BEFORE NAME (C STYLE)
      '=========
      '
      if ((a<>0)and(a<0x100))or(a>=typh)
        typ=a
        m=isptr(wm,k)
        if ascn<>lbr
          w2=tword(wm,k)
          do
            if not callingconv(wm,k,w2)
              exit do
            endif
          loop
        else
          k++           'SKIP LEFT BRACKET
          ascw=lbr
        endif
        if ascw=lbr 'NAME IN BRACKETS
          isptr(wm,k)    'SKIP *
          w2=tword(wm,k) 'NAME
          k++           'SKIP RIGHT BRACKET
          skiplspace(wm,k)
        endif
        if ascn=lbr
          if clas
            mth=3 'METH
          else
            mth=2 'FUN
          endif
          n=0x11f
        endif
        a=1
        if m
          'w2=string(m,"*")+w2 'INDIRECTION
          indi+=m : m=0
          n or=1
        endif
        if ascn=91
          a=1 : n or=2       'ARRAY
        endif
        '
        'check ahead for opening parameter bracket
        '
        if a
          w1=wordahead(wm,k)
        else
          w1=""
        endif
        skiplspace(wm,k)
      endif 'type before name tbfna
        '
      '
      pparams:   '(..) [] ARRAY OR PROCEDURE PARAMS
      '============================================
      '
      a=asc(w1)
      if (a=40)or(a=91)
        capture(wm,m,k,a)
        skiplspace(wm,k)
        w3=mid(wm,m,k-m)
        nocrs(w3)
        w1=wordahead(wm,k)
        n or=1
        if w1="as"
          k=nwd
        elseif ascn=61
          'SYNTAX: virtual void f()=0
          if a=40
            endline(wm,k) 'skip
          endif
        else
          if n<2
            wr="sys"
          endif
        endif
      endif
      '
      astype:  'AS dim type or fun type
      '================================
      '
      if w1="as"
        wr=tword(wm,k)        '
        indi+=isptr(wm,k)
        if ascn=44
          k++ 'skip comma
          skiplspace(wm,k)
        endif
      endif 'AS
      '
      'CHECK FOR CALLING CONVENTION
      '============================
      '
      if nisxn
        do
          w1=wordahead(wm,k)
          if not callingconv(wm,k,w1)
            exit do
          endif
          k=nwd
        loop
      endif
      '
      '----------------------------------------
      reagg: 'PUT THE DECLARATION BACK TOGETHER
      '========================================
      '
      'wr primary type: method or vartype
      'w2 name
      'w3 parameters (..)
      '
      'INSERT TYPE NAME AS TYPE 
      '
      if n
        '  TYPE   NAME   PARAMS
        wm=wr+" "+w2+" "+w3+mid(wm,k)
        b=1
      endif
      swd=b
      k=b+len(wr)
      '
      '
      'IS IT THE DEFAULT TYPE OR
      'IS THE TYPE SPECIFIED BY SIZE?
      '------------------------------
      '
      a=0
      if mth>0
        v=cpuw
      else
        v=val(wr)
        if v=0
          a=asc(wr)
        endif
      endif
      '
      lent=v and 15
      '
      'OTHERWISE TRY TO IDENTIFY THE TYPE
      '    
      if (v=0)and(a<>48)
        '
        n=identype(wr) 'affects indt
        '
        if (n<0)or(n=0x20)
          '
          'LOOKS LIKE A C TYPE EXPRESSION
          '------------------------------
          '
          ctype(wm,k,wr)
          v=lent : n=typ ': midspace(wm,b,k)
          '
        elseif n<typh
          '
          'A PRIMITIVE TYPE OR PART OF MULTIELEMENT
          '----------------------------------------
          '
          if n=0
            '
            'LOOKAHEAD FOR MULTI-ELEMENT 'AS'
            '
            c=swd
            a=k
            endline(wm,a)
            b=instr(k,wm," as ")
            if (b>0)and(b<a)
              w1=tword(wm,b+4)
              n=identype(w1)
              midspace(wm,b,a) 'blank
              if n
                wr=w1 : k=c
              endif
            endif
            '
            'ASSUME UNIDENTIFIED TYPE TO BE SYSTEM TYPE
            '
            if n=0
              ert=121 : ers="Unidentified element type " wr : exit subroutine
            endif
          endif 
          v=lent
          '
        else 'n>=typh
          '
          'CHECK IF POINTER TO ANOTHER STRUCTURE
          '-------------------------------------
          '
          m=n-typh
          if indi=0
            if m=qme
              ers="Type must not be a member of itself"
              ow=wr : ert=999 : exit subroutine
            endif
          endif
          '
          if drc(m).a=-33
            n=4 : v=4 'ENUMERATIONS ASSUME LONG TYPE
          endif
          '
          '
        endif 'n, typh
        '
      endif 'v=0
      int indn=indi
      sni=n 'type
      ty=wr 'type or class by name
      tv=v
      '
      '
      '
      =============
      multielement:  'LOOP POINT FOR MULTIPLE MEMBERS
      =============
      '
      if indt+indi<>0
        tv=cpuw 'POINTER
      endif
      '
      ' ELEMENTS,POINTERS AND PROCEDURES
      '---------------------------------
      '
      aml=1 'DEFAULT AS 1 ARRAY ELEMENT
      v=tv  'PRIMITIVE SIZE
      '
      'POINTER TO ANOTHER STRUCT
      '
      if (v=0)and(sni>=typh)
        goto ncompor
      endif
      '
      '
      'AUTO-ADJUST BOUNDARY ALIGNMENT (PADDING)
      '----------------------------------------
      '
      if pakd=0
        roundupc(w,v)
        if mps<v
          mps=v
        endif
      endif
      '
      a=swd
      wn=nesn+unin(uni)+tword(wm,k)
      '
      c=ascn
      '
      '
      'ALLOCATE SPACE FOR FIXED ARRAY      
      '------------------------------
      '
      if mth=0
        if (ascn=lbr)or(ascn=91)
          a=k : aml=arraysize(wm,k)
        endif
      endif
      '
      '
      'DEFAULT VALUES
      '--------------
      if ascn=61
        a=k : capts(wm,k)
        mlist+="."+wn+mid(wm,a,k-a)+cm
        midspace(wm,a,k) 'blank
      endif
      '
      '
      'COMPOSE ELEMENT RECORD
      '----------------------
      '
      c=bref
      '
      if cmo
        bref=0 'NO AUTO BYREF IN C MODE
      endif
      '
      'macro encodele() 'outputs w1 (also ws sigs sigv)
      '================================================
      '
      'PARAMS
      '
      'wm  source string
      'k   source string index
      'ty  type name
      'sni type code
      'vtl virtual pointer flag
      'atx extern / virtuality codes
      '
      scope
      int a=0,b=0,m=0
      string w2="",w3="",w4="",w5=""
      '
      'DEFAULT ELEMENT
      '---------------
      '
      ws="" 'signature
      '
      '
      'SUBS / FUNCTIONS / METHODS '8' +
      '
      if sni=0x11f
        if vtl>1
          m=9 'method
        else
          m=8 'procedure
        endif
        w5=" 0       "
      else
        if (sni>=typh)or(indt+indi>0)
          m=3 'pointer
        else
          m=1 'direct
        endif
        w5=" 0 "
      endif
      '
      skiplspace(wm,k) : b=ascn
      '
      '
      'CALLING SIGNATURE / ARRAY SIGNATURE SIG
      '---------------------------------------
      '
      w2=","
      '
      sigv="" 'DEFAULT PARAM VALUES
      'sigu="" 'DEFAULT MEMBER VALUE
      if ascn=lbr
        k++ 
        ws=buildsig(wm,k,0)
        if ert
          exit subroutine 'maketypes
        endif
        if m<8
          'ws=sigs
          ws=splitsig(ws) 'REMOVE INDIRECTION COMPONENT
        endif
        if ws
          w2=ws 'SIGNATURE
        endif
      else
        if ascn=61
          if identype(wordahead(wm,k+1))=0 'NOT A UNION =
            k++
            capts(wm,k)
          endif
        endif
      endif
      '
      '
      'RETURN SIGNATURE SOG
      '--------------------
      '
      '
      'sni = 0x01.. 0xff primitive / 0x11f procedure / 0x200.. higher type
      '
      if sni>=typh
        w3=str(sni) 'higher types (location+typh)
      elseif ty
        w3=ty
      else
        w3="," 'error?
      endif
      '
      if indn
        'return pointers
        if w3="void"
          w3="sys"
        else
          if m>=8
            w3+=string(indn,"*")
          endif
        endif
      endif
      '
      '
      'VARF CALLCONV SIG SOG
      '=====================
      'see readvals
      if aml>1
        w4=" ["+str(aml)+"]" 'MEMBER FIXED ARRAY
      endif
      '  LISTPOS  VARF      CALLING-CONV  VIRTUAL        SIG   SOG ARRAY DEFAULT VALS
      w1=     w5+str(m)+" "+chr(coco+crgd+65)+chr(atx+65)+" "+w2+" "+w3+w4+" "+sigv
      end scope
      'end macro 'codele
      '
      '
      wpr+=rmk+wn+" "+str(v)+" "+str(w)+w1+cr
      skipspace(wm,k)
      bref=c
      '
      '
      'ADD INSTRUCTION TO VIRTUAL TABLE BUILDER
      '----------------------------------------
      '
      if ctbl
        if (vtl>0)and(mth>0)
          ws=splitsig(ws)
          buil+="|te "+wn+ws+" "+hex(w)+cr 'addVTEntry(w,wn+ws)
          ttc++
        endif
      endif
      '
      '
      'CAPTURE DEFAULT MEMBER VALUES
      '
      'ADD OFFSET FOR NEXT ELEMENT
      '---------------------------
      '
      w+=v*aml
      '
      '
      'MULTI ELEMENT / PROPERTY
      '------------------------
      '
      'MEMBERS DEFINED TOGETHER EG: SYS A,B,C(10),D
      'this syntax should not be used for methods.
      '
      '
      if ascn=58
        a=k
        k++ 'SEPARATOR OR BIT FIELD
        skiplspace(wm,k)
        if isn(ascn)
          'BIT FIELD:   : 4
          icas=1 : ilc=1 : wr=bword(wm,k)
          midspace(wm,a,k) 'BLANK OUT
        endif
      endif
      if ascn=44
        k++ : nextinstruct(wm,k)
        '
        indi=isptr(wm,k)
        m=identype(wordahead(wm,k))
        if m=0
          if ascn<>61
            goto multielement 'REPEAT FOR NEXT ELEMENT
          endif
        endif
      endif
      '
      '
      'OTHERWISE NO FURTHER ELEMENTS IN (COMMA CHAINED) LIST
      '
      appe(wrb,wri,wpr)
      wpr=""
      '
      'PROCESS NEXT ELEMENT
      '--------------------
      '
      continue do
      '
      'END OF PRIMITIVES (V>0)
      '
      ncompor:
      ========
      '
      '#########
      'INHERITED
      '#########
      '  #####
      '  #####
      '  #####
      '  #####
      '  #####
      '  #####
      '  #####
      '  #####
      '  #####
      '  #####
      '#########
      '#########
      '#########
      '
      '
      'GET ELEMENT NAME (OR COMMA FOR INHERITED ELEMENTS)
      '
      '
      skiplspace(wm,k)
      if ise(ascn)
        wd=","
      else
        wd=tword(wm,k)
      endif
      '
      '
      'CHECK FOR ARRAY DEFINITION
      '--------------------------
      '
      'LOOK FOR ROUND OR SQUARE BRACKETS
      '
      if (ascn=lbr)or(ascn=91)
        aml=arraysize(wm,k) : 'ARRAY SIZE
      endif
      '
      if ascn=97
        if wordahead(wm,k)="as"
          icas=1 : ilc=1 : k=nwd : w1=bword(wm,k) ' swallow as ..
        endif
      endif
      '
      a=sni-typh 'STRUCTURE INDEX
      '
      if a>=0
        e=1
      else
        e=0
      endif
      if e=0
        ers="Undefined "+ty : ert=10 : exit subroutine
      endif
      '
      ws=mrcso(a,1)
      '
      m=instr(ws,"/\"+cr)
      '
      if vtl=0
        '
        if m
          ws=mid(ws,m+2) 'OMIT VIRTUAL SECTION IF PARENT IS NOT A CLASS
          m=0
        endif
        '
      else 'vtl<>0
        '
        if m=0
          '
          ws="/\"+cr+ws 'NO VIRTUAL SECTION DEFINED
          m=1
        else 'm<>0
          if drc(a).e 'TABLE ENTRIES PRESENT
            if ctbl
              tbls+="|ue "+
              hex(drc(a).c)+" "+  'vft table index
              hex(a)+" "+         'structure index       
              hex(aoff+w)+" "+    'target offset
              ty+cr               'type name
              'no vot
              tuc++
              if lclv=0
                aoffs=aoff
              endif
            endif
          endif
        endif
        '
      endif
      '
      '
      '--------------------------
      'SPLIT THE STRUCTURE STRING
      '==========================
      '
      wt=mid(wm,k)
      wm=""
      k=1
      '
      'INCORPORATE INHERITED BODY ELEMENT
      '
      c=0
      if vtl+m=0
        d=drc(a).f
        if mps<d
          mps=d
        endif
        roundupc(w,d) 'ADJUST BASE ALIGNMENT FOR INHERITED
        c=1 : w4=" 0 5 "
        d=drc(a).b
      else
        'if vtl
        '  c=2 : w4=" 0 6 "
        'endif
        'd=drc(a).e*cpuw 'SIZE OF VIRTUAL TABLE ENTRIES
      endif
      '
      '
      if c
        if wd<>","
          w2=rmk+nesn+wd+" "+str(d)+" "+str(w)+w4+"AA , "+ty+cr
          wm+=w2
          appe(wrb,wri,w2)
        endif
      endif
      '
      'CALC OFFSET FOR NEXT INHERITED COMPONENT. (ARRAY SPACE INCLUDED)
      '
      'calculated in advance
      '
      c=0
      if vtl
        if m
          c=4 'VIRTUAL PART OF MEMBER INTO MAIN VIRTUAL
        endif
      else 'vtl=0 'MAIN BODY
        if m=0
          c=1 'BODY OF MEMBER INTO MAIN BODY
        endif
      endif
      '
      select c
      case 0 :
        na=1
        pof=w
      case 1 : 'body part (arrays supported)
        na=aml
        pof=w+drc(a).b*aml
        roundupc(pof,drc(a).f)
      case 4 : 'virtual part (no arrays supported)
        na=1
        pof=w+drc(a).e*cpuw
      end select
      '
      '
      '
      '==================
      insert_subelements:
      '==================
      '
      '---------------------------
      'PROCESS INHERITED ELEMENTS
      '--------------------------
      '
      b=1
      '
      '
      do 'FOR EACH OF THE INHERITED ELEMENTS
        '
        wn=tword(ws,b) 'THE NAME OF THE SUB ELEMENT
        if lenw=0
          exit do
        endif
        m=ascw
        '
        '
        '---------------------------------
        'CAPTURE BODY OF INHERITED ELEMENT
        '=================================
        '
        if m=47 
          '
          'end of member vt section and start of member body
          '
          '
          if vtl>0
            '
            'CAPTURE BODY OF INHERITED COMPONENT
            '-----------------------------------
            '
            c=drc(a).f
            if mps<c
              mps=c
            endif
            vof+=drc(a).b*aml  'accum size of objects
            roundupc(vof,c)
            '
            'CHECK FIRST IF THERE ARE ANY ELEMENTS IN THE BODY
            '-------------------------------------------------
            '
            b++ : nextinstruct(ws,b) '/\
            '
            if len(ws)>=b
              wih+=" ?"+str(a)+" "+ty+" "+str(aml)+" "+wd+" "+mid(ws,b)
            endif
            '
          endif
          '
          ws=""
          exit do ' END OF PASS 1 WITH CAPTURED BODY
          '
          'previously held over for the body section
          'It is assumed that we are in in the parental body section.
          '
          '
        elseif m=63
          '
          '
          'INSERT BODY OF INHERITED SUBELEMENTS INTO MAIN BODY ('?' MARKER)
          '----------------------------------------------------------------
          '
          a=val(tword(ws,b))   'index to type
          ty=tword(ws,b)        'type
          aml=val(tword(ws,b)) 'array / single scale
          wd=tword(ws,b)        'type/inherited structure
          wn=tword(ws,b)        'name
          d=0
          if atx>0
            if (pof=cpuw)and(ascw=95)
              if (wd=",")and(wn="___")
                d=1 : pof=0
              endif
             endif
          endif
          '
          'BODY OFFSET (allowing for arrays)
          '
          c=drc(a).f
          if mps<c
            mps=c
          endif
          roundupc(pof,c)
          w=pof
          pof+=drc(a).b*aml
          roundupc(pof,c)
          if d
            endline(ws,b) : continue do 'OMIT FIRST VTP (COMPAT WITH SIH)
          endif
          '
          '
          'INCORPORATE INHERITED STRUCTURE NAME
          '
          '
          'A HEADER IS ADDED DESCRIBING THE WHOLE INHERITED STRUCTURE
          '
          if wd<>","
            '
            'another of these may be present in the virtual section.
            w2=rmk+nesn+wd+" "+str(drc(a).b)+" "+str(w)+" 0 5 "+ "AA , "+ty+cr
            appe(wrb,wri,w2)
          endif
          '
        endif 'm=63 '?'
        '
        'READ ATTRIBUTES OF EACH INHERITED ELEMENT
        'Recalculate offsets make other adjustments.
        'applies to both virtual and body sections.
        '
        pv=v
        x=readint(ws,b)     'SIZE
        v=readint(ws,b)     'OFFSET
        w3=yword(ws,b)      'PROCLIST POSITION (PLP)
        w4=yword(ws,b)      'VAR/FUNCTION CODE (VARF)
        c=b : endline(ws,b) 'itr multiline default values
        w5=mid(ws,c,b-c)    'REMAINING ATTRIBUTES
        '
        '
        'CHECK MAX PRIMITIVE SIZE
        '
        n=val(w4) 'varf
        '
        '
        'ADJUST VAR/FUNCTION CODE VARF
        '-----------------------------
        '
        if vtl 
          m=n
          '
          if sih=0
            if n=9
              n=10 '9 SIGNIFIES INHERITED METHOD
            endif
            if n>=10
              n+=vof
            endif
          endif
          '
          if n<>m
            w4=str(n) 'CONVERT BACK TO STRING
          endif
        endif
        '
        'PREFIX NAME DOT TO GIVE THE LOCAL NAME
        '
        if wd<>","
          wn=wd+"."+wn 'IF WD IS A COMMA THEN USE THE ORIGINAL NAME
        endif
        '
        '
        'APPEND RECOMPOSED DESCRIPTOR
        '-----------------------------
        '
        'start with tab
        'add element with adjusted offset
        c=w+v 'oop total offset
        w3=" "+str(x)+" "+str(c)+" "+w3+" "+w4+" "+w5+cr
        '
        w2=rmk+unin(uni)+nesn+wn+w3
        appe(wrb,wri,w2)
        '
      loop ' FOR EACH INHERITED SUB ELEMENT
      '
      'pass 1: class virtual table members (early exit)
      'pass 2: object members
      '
      '
      w=pof 'ALIGNED OFFSET AFTER MEMBER(S)
      wm=wt
      k=1
      sih=0
      '
      'MORE NAMES TO FOLLOW?
      '---------------------
      '
      nextinstruct(wm,k)
      '
      'check for comma (or semicolons in C style structures)
      '
      if ascn=58
        k++
      elseif ascn=44
        k++
        wr=wordahead(wm,k)
        a=asc(wm,nwd)
        if isx(a)
          goto multielement 'loop back to process similar members
        endif
        'otherwise assume a new type
      endif
      '
    '===================================
    loop 'EACH ELEMENT IN MAIN STRUCTURE
    '===================================
    '
    '
    'STORE COMPLETED DATA STRUCTURE
    '==============================
    '
    wm=left(wrb,wri)
    b=qme
    mrcsi(wm,b,1)     'CLASS STRUCTURE RECORD
    mrcsi(mlist,b,2)  'MEMBER LIST (INHERITED)
    '
    if wmx>w
      w=wmx           'MAX SIZE FOR UNIONS
    endif
    if pakd=0
      roundupc(w,mps) 'ROUND UP TO NEAREST MAX PRIMITIVE SIZE
    endif
    drc(b).b=w        'LENGTH OF STRUCTURE
    if ctbl
      drc(b).c=me     'INTERNAL VIRTUAL TABLE INDEX
    endif
    drc(b).d=atx      'EXTERN / VIRTUAL TABLE FLAGS
    drc(b).f=mps      'MAX PRIMITIVE SIZE
    '
    '
    'SOURCE LISTING
    '
    if vew>0
      appendt(cr+sp+"TYPE: "+mrcso(b,0)+cr+cr+mrcso(b,1)+cr+"END TYPE"+ep)
    endif
    '
    'VIRTUAL TABLE BUILDER
    '=====================
    '
    if ctbl
      '
      'STATIC VFT BUILDER TO GO AT BOTTOM OF METHODS BLOCK
      '
      a=lclv
      if a
        staticvars()
      endif
      '
      if buil
        'lea rcx,[ebx+????] ...
        buil="lea "+qecx+cm+memreg(regs,aoff)+
        cr+buil+cr
        'no vot
      endif
      '
      wm=""
      mrcsi("._mt_"+cr+tbls+buil,b,3)
      '
      'DECLARE THE VACANT VIRTUAL FUNCTION TABLE IMMEDIATELY AFTER CLASS
      'ASSUME STATIC TABLE
      w1="sys "+mrcso(b,0)+"_table"
      vars(w1)
      c=drc(b).e * cpuw 'space for method addresses
      aoff+=c           'MAKE STEALTH ARRAY -- no vot
      aoffs=aoff
      'okq
      '
      if a
        localvars()
      endif
      '
    endif 'ctbl
    '
    '
    end subroutine 'MakeTypes




