home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 August / PCWorld_2000-08_cd.bin / Software / TemaCD / xbasic / xbpro.exe / xb / qbtoxb.x < prev    next >
Text File  |  1999-12-29  |  122KB  |  2,805 lines

  1. '
  2. '
  3. ' ####################  QuickBasic to XBasic translator
  4. ' #####  PROLOG  #####  copyright 1999
  5. ' ####################  Max Reason
  6. '
  7. PROGRAM    "qbtoxb"
  8. VERSION    "0.0060"
  9. '
  10. IMPORT    "xma"
  11. IMPORT    "xst"
  12. IMPORT    "xgr"
  13. IMPORT    "xui"
  14. '
  15. ' This software is "open source", subject to the terms and conditions
  16. ' of the GPU = "GNU general public license", which is reproduced at
  17. ' http://www.opensource.org/licenses/gpl-license.html .
  18. '
  19. ' Microsoft distributes a stripped-down QuickBasic product called QBasic,
  20. ' but throughout this program, qbasic and QBasic always refer-to QuickBasic.
  21. '
  22. ' This program is currently work-in-progress and far from functional.
  23. '
  24. ' This following summarizes the flow of this program.
  25. '
  26. '    Entry()                                                    ' the entry function - start here
  27. '        LoadQBasicProgram()                        ' load QBasic program into qbasic$[]
  28. '        QBasicToXBasic()                            ' translate qbasic$[] source into xbasic$[]
  29. '            Initialize()                                ' initialize everything that needs initializing
  30. '                InitializeVariables()            ' create and initialize fundamental variables and arrays
  31. '                InitializeQBasicTokens()    ' defines all QBasic language-defined symbols and tokens
  32. '                InitializeXBasicTokens()    ' defines all XBasic language-defined symbols and tokens
  33. '                InitializeQBasicTokens()    ' adds XBasic-equivalent-tokens to QBasic tokens
  34. '                InitializeXBasicTokens()    ' pass #2 probably not necessary for XBasic
  35. '                ParseQBasic()                            ' parse QBasic source-code into tokens
  36. '                    CallsManyFunctions             ' ParseQBasic() calls many functions
  37. '                Translate()                                ' translate tokens into XBasic source
  38. '                    TranslateLine()                    ' translate line of tokens to XBasic
  39. '                    CallsManyFunctions            ' Translate() calls many functions
  40. '
  41. '
  42. ' Parsing a QuickBasic program creates an array of token-numbers
  43. ' in three-dimensional array #program[function,line,token].
  44. ' The lower 24-bits of a token is the token-number, which gives
  45. ' access to information about the token at #token[token-number].
  46. ' The upper 8-bits of a token contains leading-whitespace info.
  47. ' See the TOKEN composite data-type declaration below for details.
  48. '
  49. '
  50. ' #######################################
  51. ' #####  composite/structure types  #####
  52. ' #######################################
  53. '
  54. ' TOKEN variables hold both QBasic and XBasic tokens.
  55. '
  56. TYPE TOKEN                                '
  57.     XLONG            .token                ' token number in #token[]
  58.     XLONG            .string                ' string number in #string$[]
  59.     XLONG            .length                ' length of string in characters
  60.     XLONG            .function            ' function number this string is in
  61.     XLONG            .hashback            ' previous token with same hash
  62.     XLONG            .hashnext            ' next token with same hash
  63.     XLONG            .kindback            ' previous token of same kind
  64.     XLONG            .kindnext            ' next token of same kind
  65.     XLONG            .first                ' first executable line in source
  66.     XLONG            .final                ' final executable line in source
  67.     XLONG            .hash                    ' hash value of this string
  68.     XLONG            .kind                    ' statement, operator, etc.
  69.     XLONG            .type                    ' data-type - SBYTE, UBYTE, SSHORT, USHORT, etc.
  70.     XLONG            .scope                ' scope of allocation - AUTO, STATIC, SHARED, EXTERNAL
  71.     XLONG            .translate        ' translate token - in other language
  72.     XLONG            .address            ' address in memory
  73.     XLONG            .akind[15]        ' argument kinds
  74.     XLONG            .atype[15]        ' argument data-types
  75.     GIANT            .ivalue                ' any integer-type value
  76.     DOUBLE        .fvalue                ' floating-point value
  77.     XLONG            .lineq                ' function source line - QB
  78.     XLONG            .linex                ' function source line - XB
  79.     XLONG            .reserve54        '
  80.     XLONG            .reserve55        '
  81.     XLONG            .reserve56        '
  82.     XLONG            .reserve57        '
  83.     XLONG            .reserve58        '
  84.     XLONG            .reserve59        '
  85.     XLONG            .reserve60        '
  86.     XLONG            .reserve61        '
  87.     XLONG            .reserve62        '
  88.     XLONG            .reserve63        '
  89. END TYPE
  90. '
  91. '
  92. ' #######################
  93. ' #####  functions  #####
  94. ' #######################
  95. '
  96. DECLARE FUNCTION  Entry                   ()
  97. DECLARE FUNCTION  Initialize              ()
  98. DECLARE FUNCTION  InitializeVariables     ()
  99. DECLARE FUNCTION  InitializeQBasicTokens  ()
  100. DECLARE FUNCTION  InitializeXBasicTokens  ()
  101. DECLARE FUNCTION  LoadQBasicProgram       (@qbasic$[])                                ' find and load QBasic program
  102. DECLARE FUNCTION  QBasicToXBasic          (@qbasic$[], @xbasic$[])        ' translate QBasic to XBasic
  103. DECLARE FUNCTION  ParseQBasic             ()                                                    ' parse QBasic program to create tokens
  104. DECLARE FUNCTION  Translate               ()                                                    ' translate program tokens to XBasic source
  105. DECLARE FUNCTION  TranslateLine           (@line[])                                        ' translate line of tokens to XBasic source
  106. DECLARE FUNCTION  TranslateStatement            (@line[], @offset)                    ' translate statement on line to XBasic source
  107. '
  108. DECLARE FUNCTION  DeparseTokens           (@token[], @line$)                    ' convert tokens into line of source
  109. DECLARE FUNCTION  ParseSourceLine         (@line$, @line[])                        ' parse source line into tokens
  110. DECLARE FUNCTION  ParseWhitespace         (@line$, @offset)                        ' parse whitespace characters
  111. DECLARE FUNCTION  ParseCharacter          (@line$, @offset)                        ' parse special character (operators, etc)
  112. DECLARE FUNCTION  ParseNumber             (@line$, @offset)                        ' parse numeric string
  113. DECLARE FUNCTION  ParseSymbol             (@line$, @offset)                        ' parse symbol
  114. DECLARE FUNCTION  GetSymbol               (@line$, @offset, @symbol$)    ' get symbol
  115. DECLARE FUNCTION  OutputToken             (@token)                                        ' output token
  116. DECLARE FUNCTION  TestForKeyword          (@symbol$)                                    ' keyword?
  117. DECLARE FUNCTION  MinTypeFromGiant        (value$$)                                        ' integer type
  118. DECLARE FUNCTION  MinTypeFromDouble       (value#)                                        ' float type
  119. '
  120. DECLARE FUNCTION  AddKeyword              (translate, function, scope, kind, type, atype1, atype2, atype3, @string$)
  121. DECLARE FUNCTION  FindToken               (@match[], function, scope, kind, type, atype1, atype2, atype3, @string$)
  122. DECLARE FUNCTION  AddToken                (@token, function, scope, kind, type, atype1, atype2, atype3, @string$)
  123. DECLARE FUNCTION  OutputXBasic            (@text$[])
  124. DECLARE FUNCTION  TokenRestOfLine         ()
  125. DECLARE FUNCTION  PrintTokens             ()
  126. DECLARE FUNCTION  PrintHash               ()
  127. DECLARE FUNCTION  Terminate               ()
  128. '
  129. '
  130. '
  131. ' ##############################
  132. ' #####  shared constants  #####
  133. ' ##############################
  134. '
  135.     $$TYPE_NONE                            = 0x00000000    ' NONE - type unknown
  136.     $$TYPE_VOID                            = 0x00000001    ' VOID - type prohibited
  137.     $$TYPE_SBYTE                        = 0x00000002    ' SBYTE - 8-bit signed integer
  138.     $$TYPE_UBYTE                        = 0x00000003    ' UBYTE - 8-bit unsigned integer
  139.     $$TYPE_SSHORT                        = 0x00000004    ' SSHORT - 16-bit signed integer
  140.     $$TYPE_USHORT                        = 0x00000005    ' USHORT - 16-bit unsigned integer
  141.     $$TYPE_SLONG                        = 0x00000006    ' SLONG - 32-bit signed integer
  142.     $$TYPE_ULONG                        = 0x00000007    ' ULONG - 32-bit unsigned integer
  143.     $$TYPE_XLONG                        = 0x00000008    ' XLONG - CPU integer
  144.     $$TYPE_GOADDR                        = 0x00000009    ' GOADDR - label address
  145.     $$TYPE_SUBADDR                    = 0x0000000A    ' SUBADDR - subroutine address
  146.     $$TYPE_FUNCADDR                    = 0x0000000B    ' FUNCADDR - function address
  147.     $$TYPE_GIANT                        = 0x0000000C    ' GIANT - 64-bit signed integer
  148.     $$TYPE_SINGLE                        = 0x0000000D    ' SINGLE - IEEE 32-bit
  149.     $$TYPE_DOUBLE                        = 0x0000000E    ' DOUBLE - IEEE 64-bit
  150.     $$TYPE_UNDEFINED                = 0x0000000F    '
  151.     $$TYPE_STRING                        = 0x00000013    ' STRING - string/array of UBYTEs
  152.     $$TYPE_STRING_ASCII            = 0x00000013    ' STRING - string/array of UBYTEs
  153.     $$TYPE_STRING_UNICODE        = 0x00000015    ' UNICODE - string/array of USHORTs
  154.     $$TYPE_COMPOSITE_FIRST    = 0x00000020    ' first composite type
  155.     $$TYPE_COMPOSITE_FINAL    = 0x0000FFFF    ' final composite type
  156. '
  157.     $$FORM_BIT                            = 0x00010001    ' 0b01001101
  158.     $$FORM_OCTAL                        = 0x00010002    ' 0o01234567
  159.     $$FORM_DECIMAL                    = 0x00010003    ' 1234567890
  160.     $$FORM_HEXADECIMAL            = 0x00010004    ' 0x0123456789ABCDEF or &H0123456789ABCDEF
  161. '
  162.     $$KIND_NONE                            = 0x00000000    ' kind unknown
  163.     $$KIND_STATEMENT                = 0x00000001    ' language statement
  164.     $$KIND_INTRINSIC                = 0x00000002    ' intrinsic function
  165.     $$KIND_OPERATOR                    = 0x00000004    ' OR  AND  XOR  +  -  *  \  /  etc.
  166.     $$KIND_KEYWORD                    = 0x00000008    '
  167.     $$KIND_LABEL                        = 0x00000010    ' GOTO label
  168.     $$KIND_SUBNAME                    = 0x00000020    ' GOSUB subname
  169.     $$KIND_FUNCTION                    = 0x00000040    ' function in program
  170.     $$KIND_TYPE                            = 0x00000080    ' data-type
  171.     $$KIND_SYMBOL                        = 0x00000100    ' unknown kind of symbol
  172.     $$KIND_LITERAL                    = 0x00000200    ' number or string
  173.     $$KIND_CHARCON                    = 0x00000400    ' character constant - as in 'a'
  174.     $$KIND_CONSTANT                    = 0x00000800    ' user-defined constant
  175.     $$KIND_VARIABLE                    = 0x00001000    ' simple variable
  176.     $$KIND_ARRAY                        = 0x00002000    ' array variable
  177.     $$KIND_COMPOSITE        = 0x00004000    ' structure symbol
  178.     $$KIND_ELEMENT                    = 0x00008000    ' structure element
  179.     $$KIND_COMMENT                    = 0x00010000    ' rest of the line
  180.     $$KIND_CHARACTER                = 0x00020000    ' : ; , ( )
  181.     $$KIND_WHITESTRING            = 0x00040000    ' string of whitespace
  182.     $$KIND_AVAILABLE_19            = 0x00080000    '
  183.     $$KIND_AVAILABLE_20            = 0x00100000    '
  184.     $$KIND_AVAILABLE_21            = 0x00200000    '
  185.     $$KIND_AVAILABLE_22            = 0x00400000    '
  186.     $$KIND_AVAILABLE_23            = 0x00800000    '
  187.     $$KIND_AVAILABLE_24            = 0x01000000    '
  188.     $$KIND_AVAILABLE_25            = 0x02000000    '
  189.     $$KIND_AVAILABLE_26            = 0x04000000    '
  190.     $$KIND_AVAILABLE_27            = 0x08000000    '
  191.     $$KIND_AVAILABLE_28            = 0x10000000    '
  192.     $$KIND_AVAILABLE_29            = 0x20000000    '
  193.     $$KIND_QBASIC                        = 0x40000000    ' QBasic language element
  194.     $$KIND_XBASIC                        = 0x80000000    ' XBasic language element
  195. '
  196.     $$SCOPE_NONE                        = 0x00000000    ' scope unknown
  197.     $$SCOPE_AUTO                        = 0x00000001    ' function and temporary
  198.     $$SCOPE_AUTOX                        = 0x00000002    ' function and temporary
  199.     $$SCOPE_STATIC                    = 0x00000003    ' function and permanent
  200.     $$SCOPE_SHARED                    = 0x00000004    ' program and permanent
  201.     $$SCOPE_SHARED_NAME            = 0x00000005    ' program and permanent - sharename
  202.     $$SCOPE_EXTERNAL                = 0x00000006    ' modules and permanent - static linked modules
  203.     $$SCOPE_EXTERNAL_NAME        = 0x00000007    ' modules and permanent - static linked modules - sharename
  204. '
  205.     $$MIN_SBYTE                = -128
  206.     $$MAX_SBYTE                = 127
  207.     $$MIN_UBYTE                = 0
  208.     $$MAX_UBYTE                = 255
  209.     $$MIN_SSHORT            = -32768
  210.     $$MAX_SSHORT            = 32767
  211.     $$MIN_USHORT            = 0
  212.     $$MAX_USHORT            = 65535
  213.     $$MIN_SLONG                = -2147483648
  214.     $$MAX_SLONG                = 2147483647
  215.     $$MIN_ULONG                = 0
  216.     $$MAX_ULONG                = 4294967395$$
  217.     $$MIN_XLONG                = $$MIN_SLONG
  218.     $$MAX_XLONG                = $$MAX_ULONG
  219.     $$MIN_GOADDR            = $$MIN_XLONG
  220.     $$MAX_GOADDR            = $$MAX_XLONG
  221.     $$MIN_SUBADDR            = $$MIN_XLONG
  222.     $$MAX_SUBADDR            = $$MAX_XLONG
  223.     $$MIN_FUNCADDR        = $$MIN_XLONG
  224.     $$MAX_FUNCADDR        = $$MAX_XLONG
  225.     $$MIN_SINGLE            = 0sFF7FFFFF
  226.     $$MAX_SINGLE            = 0s7F7FFFFF
  227.     $$MIN_DOUBLE            = 0dFFEFFFFFFFFFFFFF
  228.     $$MAX_DOUBLE            = 0d7FEFFFFFFFFFFFFF
  229.     $$MIN_GIANT                = 0x8000000000000000
  230.     $$MAX_GIANT                = 0x7FFFFFFFFFFFFFFF
  231. '
  232. '
  233. ' ##############################
  234. ' #####  shared variables  #####
  235. ' ##############################
  236. '
  237.     TOKEN        #toktemp                        ' temporary - for compiler tests
  238.     XLONG        #print                            ' temporary - for debugging
  239. '
  240.     XLONG        #pass                                ' pass # for parse or compile
  241.     XLONG        #line                                ' current line in function
  242.     XLONG        #token                            ' current token on line
  243.     XLONG        #function                        ' function being parsed or translated
  244.     XLONG        #whitebyte                    ' whitestring # = entry in #whitestring$[]
  245. '
  246.     XLONG        #ustring                        ' upper-bound of #string$[]
  247.     XLONG        #nstring                        ' next slot in #string$[]
  248.     XLONG        #utoken                            ' upper-bound of #token[]
  249.     XLONG        #ntoken                            ' next slot in #token[]
  250. '
  251.     XLONG        #quline                            ' upper QBasic source-code line
  252.     XLONG        #qnline                            ' next QBasic source-code line
  253.     XLONG        #xuline                            ' upper XBasic source-code line
  254.     XLONG        #xnline                            ' next XBasic source-code line
  255. '
  256.     XLONG        #qatoken                        ' first QBasic keyword token-number
  257.     XLONG        #qztoken                        ' final QBasic keyword token-number
  258.     XLONG        #xatoken                        ' first XBasic keyword token-number
  259.     XLONG        #xztoken                        ' final XBasic keyword token-number
  260. '
  261.     USHORT    #hx[]                                ' hash mixer
  262.     XLONG        #hash[]                            ' hash table
  263.     XLONG        #kind[]                            ' first token of each kind
  264.     TOKEN        #token[]                        ' holds all symbol-table tokens
  265.     STRING    #string$[]                    ' holds all symbol-table strings
  266.     XLONG        #program[]                    ' holds token-numbers for entire program : #program[function,line,token]
  267.     XLONG        #functoken[]                ' holds token-number of every function in the program
  268.     XLONG        #whitetoken[]                ' token-numbers of 256 leading-whitespace strings representable in upper-byte of tokens
  269. '
  270.     STRING    #qbasic$[]                    ' holds entire QBasic source program
  271.     STRING    #xbasic$[]                    ' holds entire XBasic source program
  272. '
  273. ' the following arrays test and/or convert characters in a single array access
  274. '
  275.     UBYTE        #charsetSymbolFirst[]
  276.     UBYTE        #charsetSymbolInner[]
  277.     UBYTE        #charsetSymbolFinal[]
  278.     UBYTE        #charsetSymbol[]
  279.     UBYTE        #charsetUpper[]
  280.     UBYTE        #charsetLower[]
  281.     UBYTE        #charsetNumeric[]
  282.     UBYTE        #charsetUpperLower[]
  283.     UBYTE        #charsetUpperNumeric[]
  284.     UBYTE        #charsetLowerNumeric[]
  285.     UBYTE        #charsetUpperLowerNumeric[]
  286.     UBYTE        #charsetUpperToLower[]
  287.     UBYTE        #charsetLowerToUpper[]
  288.     UBYTE        #charsetVex[]
  289.     UBYTE        #charsetHexUpper[]
  290.     UBYTE        #charsetHexLower[]
  291.     UBYTE        #charsetHexUpperLower[]
  292.     UBYTE        #charsetHexUpperToLower[]
  293.     UBYTE        #charsetHexLowerToUpper[]
  294.     UBYTE        #charsetBackslash[]
  295.     UBYTE        #charsetBackslashByte[]
  296.     UBYTE        #charsetBackslashChar[]
  297.     UBYTE        #charsetNormalChar[]
  298.     UBYTE        #charsetOctal[]
  299.     UBYTE        #charsetPrintChar[]
  300.     UBYTE        #charsetSuffix[]
  301.     UBYTE        #charsetSpaceTab[]
  302.     UBYTE        #charsetWhitespace[]
  303. '
  304. '
  305. ' ######################
  306. ' #####  Entry ()  #####
  307. ' ######################
  308. '
  309. FUNCTION  Entry ()
  310. '
  311.     XstGetConsoleGrid (@console)
  312.     XgrGetDisplaySize ("", @#displayWidth, @#displayHeight, @#windowBorderWidth, @#windowTitleHeight)
  313.     maxwidth = #displayWidth - #windowBorderWidth - #windowBorderWidth
  314.     XuiSendStringMessage (console, @"GetSize", @x, @y, @w, @h, 0, 0)
  315.     width = MIN (maxwidth, 1016)
  316.     height = h
  317. '
  318. ' set console width for printing speed efficiency and smoothness
  319. '
  320.     XuiSendStringMessage (console, @"Resize", 0, 0, width, height, 0, 0)
  321. '
  322.     LoadQBasicProgram (@qbasic$[])                        ' load QBasic program into qbasic$[]
  323.     QBasicToXBasic (@qbasic$[], @xbasic$[])        ' translate qbasic$[] into xbasic$[]
  324. END FUNCTION
  325. '
  326. '
  327. ' ###########################
  328. ' #####  Initialize ()  #####
  329. ' ###########################
  330. '
  331. FUNCTION  Initialize ()
  332. '
  333.     #print = 1
  334. '
  335.     #pass = 0                                            '
  336.     InitializeVariables ()                ' create arrays for tokens, symbols, etc.
  337. '
  338.     #pass = 1
  339.     #ntoken = 0                                        ' zero token number
  340.     #nstring = 0                                    ' zero string number
  341.     InitializeXBasicTokens ()            ' pass 1 cannot fill-in equivalent QBasic tokens
  342.     InitializeQBasicTokens ()            ' pass 1 cannot fill-in equivalent XBasic tokens
  343. '
  344.     #pass = 2
  345.     #ntoken = 0                                        ' zero token number
  346.     #nstring = 0                                    ' zero string number
  347.     InitializeXBasicTokens ()            ' pass 2 can fill-in equivalent QBasic tokens
  348.     InitializeQBasicTokens ()            ' pass 2 can fill-in equivalent XBasic tokens
  349. '
  350.     #pass = 0                                            '
  351.     IF #print THEN PrintTokens ()    ' look at the tokens
  352. '
  353.     IF #print THEN
  354.         PRINT "               "; HEX$(#xatoken,4);; HEX$(#xztoken,4);; HEX$(#qatoken,4);; HEX$(#qztoken,4)
  355.         PRINT
  356.         PrintHash ()                                ' look at hash table
  357.     END IF
  358. END FUNCTION
  359. '
  360. '
  361. ' ####################################
  362. ' #####  InitializeVariables ()  #####
  363. ' ####################################
  364. '
  365. FUNCTION  InitializeVariables ()
  366. '
  367.     #nwhite = 0                                                ' start at white 0
  368.     #ntoken = 0                                                ' start at token 0
  369.     #nstring = 0                                            ' start at string 0
  370.     #function = 0                                            ' start with PROLOG
  371. '
  372.     #uhash = 255                                            ' 8-bit hash size for now
  373.     #uwhite = 255                                            ' maximum of 255 whitestrings
  374.     #utoken = 4095                                        ' start with room for 4096 tokens
  375.     #ustring = 4095                                        ' start with room for 4096 strings
  376.     #ufunction = 1023                                    ' start with room for 1024 functions
  377.     #uwhitestring = 255                                ' never more than 255 leading-whitestring tokens
  378. '
  379.     DIM #hx[255]                                            ' dimension hash mix
  380.     DIM #hash[#uhash]                                    ' dimension hash array
  381.     DIM #token[#utoken]                                ' dimension token array
  382.     DIM #string$[#ustring]                        '    dimension string array
  383.     DIM #program[#ufunction,]                    ' dimension program array
  384.     DIM #functoken[#ufunction]                ' dimension function array
  385.     DIM #whitetoken[#uwhitestring]        ' dimension whitetoken array
  386.     DIM #whitestring$[#uwhitestring]    ' dimension whitestring array
  387. '
  388.     #hx[  0] = 0xF3C9    : #hx[ 64] = 0x811D    : #hx[128] = 0x199C    : #hx[192] = 0xD0C8
  389.     #hx[  1] = 0xE034    : #hx[ 65] = 0xC6E3    : #hx[129] = 0x1299    : #hx[193] = 0x3C07
  390.     #hx[  2] = 0xB37C    : #hx[ 66] = 0xCA5D    : #hx[130] = 0xA314    : #hx[194] = 0xDDCA
  391.     #hx[  3] = 0x4E31    : #hx[ 67] = 0x5AF2    : #hx[131] = 0xEF45    : #hx[195] = 0xB2C1
  392.     #hx[  4] = 0xC0DE    : #hx[ 68] = 0xB2F3    : #hx[132] = 0xEFC3    : #hx[196] = 0x6A7C
  393.     #hx[  5] = 0x2487    : #hx[ 69] = 0xCF28    : #hx[133] = 0x8A2D    : #hx[197] = 0x5E02
  394.     #hx[  6] = 0x98E2    : #hx[ 70] = 0x4714    : #hx[134] = 0x2553    : #hx[198] = 0x4C8B
  395.     #hx[  7] = 0x557C    : #hx[ 71] = 0x32B0    : #hx[135] = 0x8CA6    : #hx[199] = 0x6652
  396.     #hx[  8] = 0xA6CB    : #hx[ 72] = 0x9A76    : #hx[136] = 0x60B8    : #hx[200] = 0x3C50
  397.     #hx[  9] = 0x410D    : #hx[ 73] = 0xB2A4    : #hx[137] = 0x2192    : #hx[201] = 0x02B8
  398.     #hx[ 10] = 0x7767    : #hx[ 74] = 0xDE9B    : #hx[138] = 0xA15C    : #hx[202] = 0x7B70
  399.     #hx[ 11] = 0x3861    : #hx[ 75] = 0xE0E1    : #hx[139] = 0xA527    : #hx[203] = 0x118F
  400.     #hx[ 12] = 0x5517    : #hx[ 76] = 0xA7C3    : #hx[140] = 0x1FAC    : #hx[204] = 0xEF65
  401.     #hx[ 13] = 0x0918    : #hx[ 77] = 0x0E48    : #hx[141] = 0xC554    : #hx[205] = 0x3D6E
  402.     #hx[ 14] = 0xF3AF    : #hx[ 78] = 0xFABE    : #hx[142] = 0x5ECB    : #hx[206] = 0xCAB2
  403.     #hx[ 15] = 0x2EAB    : #hx[ 79] = 0xE351    : #hx[143] = 0x7941    : #hx[207] = 0x23F0
  404.     #hx[ 16] = 0x210D    : #hx[ 80] = 0x4419    : #hx[144] = 0x3EA2    : #hx[208] = 0x927F
  405.     #hx[ 17] = 0xDF19    : #hx[ 81] = 0x5AB4    : #hx[145] = 0xE73D    : #hx[209] = 0x1F12
  406.     #hx[ 18] = 0x2F0B    : #hx[ 82] = 0xDDF9    : #hx[146] = 0xDE62    : #hx[210] = 0xEDCE
  407.     #hx[ 19] = 0x269A    : #hx[ 83] = 0x513E    : #hx[147] = 0x9FFA    : #hx[211] = 0x0D52
  408.     #hx[ 20] = 0xE171    : #hx[ 84] = 0x1BDF    : #hx[148] = 0x0CE8    : #hx[212] = 0x69B5
  409.     #hx[ 21] = 0x8D07    : #hx[ 85] = 0xA0BC    : #hx[149] = 0x8683    : #hx[213] = 0x9DC4
  410.     #hx[ 22] = 0x0AF1    : #hx[ 86] = 0xC2E5    : #hx[150] = 0x481C    : #hx[214] = 0x910F
  411.     #hx[ 23] = 0x4627    : #hx[ 87] = 0x5917    : #hx[151] = 0x80E4    : #hx[215] = 0xEE6D
  412.     #hx[ 24] = 0x7C4B    : #hx[ 88] = 0x0448    : #hx[152] = 0xC43E    : #hx[216] = 0xA0E7
  413.     #hx[ 25] = 0xA59A    : #hx[ 89] = 0xE110    : #hx[153] = 0x7830    : #hx[217] = 0xF2ED
  414.     #hx[ 26] = 0x561F    : #hx[ 90] = 0xA4C8    : #hx[154] = 0x3952    : #hx[218] = 0x6EA2
  415.     #hx[ 27] = 0x1F90    : #hx[ 91] = 0x5BC6    : #hx[155] = 0x2BBA    : #hx[219] = 0xFEFC
  416.     #hx[ 28] = 0x9407    : #hx[ 92] = 0x1250    : #hx[156] = 0x476D    : #hx[220] = 0x0A20
  417.     #hx[ 29] = 0xAAAA    : #hx[ 93] = 0x3D09    : #hx[157] = 0xF307    : #hx[221] = 0xA568
  418.     #hx[ 30] = 0x404B    : #hx[ 94] = 0xD230    : #hx[158] = 0x5A6A    : #hx[222] = 0xB90E
  419.     #hx[ 31] = 0xCCB2    : #hx[ 95] = 0x19F1    : #hx[159] = 0x232A    : #hx[223] = 0xFA26
  420.     #hx[ 32] = 0xB6B8    : #hx[ 96] = 0x28D0    : #hx[160] = 0x36DA    : #hx[224] = 0xFB8E
  421.     #hx[ 33] = 0x93E5    : #hx[ 97] = 0x0FD7    : #hx[161] = 0x1448    : #hx[225] = 0x3091
  422.     #hx[ 34] = 0xCD83    : #hx[ 98] = 0x79BD    : #hx[162] = 0x016A    : #hx[226] = 0x56A1
  423.     #hx[ 35] = 0x8392    : #hx[ 99] = 0xE856    : #hx[163] = 0xF0CC    : #hx[227] = 0x184A
  424.     #hx[ 36] = 0x951B    : #hx[100] = 0xDDDE    : #hx[164] = 0x5328    : #hx[228] = 0xDEC0
  425.     #hx[ 37] = 0x983F    : #hx[101] = 0xBD28    : #hx[165] = 0x8B83    : #hx[229] = 0xC39F
  426.     #hx[ 38] = 0x1BB3    : #hx[102] = 0xD9F7    : #hx[166] = 0x1566    : #hx[230] = 0xBED3
  427.     #hx[ 39] = 0x40A7    : #hx[103] = 0xCBB9    : #hx[167] = 0xB0D3    : #hx[231] = 0x51F5
  428.     #hx[ 40] = 0x5D7E    : #hx[104] = 0x9B85    : #hx[168] = 0xCE2F    : #hx[232] = 0xC0E9
  429.     #hx[ 41] = 0x65A1    : #hx[105] = 0x82DC    : #hx[169] = 0x30FA    : #hx[233] = 0x617B
  430.     #hx[ 42] = 0x8576    : #hx[106] = 0x67B0    : #hx[170] = 0x49C6    : #hx[234] = 0xF6E9
  431.     #hx[ 43] = 0xAC39    : #hx[107] = 0x8720    : #hx[171] = 0x94D9    : #hx[235] = 0x9775
  432.     #hx[ 44] = 0xFE04    : #hx[108] = 0x0CDF    : #hx[172] = 0xE69B    : #hx[236] = 0xD5A5
  433.     #hx[ 45] = 0x6C6F    : #hx[109] = 0xA884    : #hx[173] = 0x7B2C    : #hx[237] = 0xF7D3
  434.     #hx[ 46] = 0x838F    : #hx[110] = 0x238D    : #hx[174] = 0x340B    : #hx[238] = 0x2BD5
  435.     #hx[ 47] = 0xDA44    : #hx[111] = 0xACED    : #hx[175] = 0x2E46    : #hx[239] = 0xBB3D
  436.     #hx[ 48] = 0x7B93    : #hx[112] = 0x773B    : #hx[176] = 0xFD83    : #hx[240] = 0x1483
  437.     #hx[ 49] = 0x851E    : #hx[113] = 0x84F1    : #hx[177] = 0xB1A9    : #hx[241] = 0x5906
  438.     #hx[ 50] = 0xD23F    : #hx[114] = 0xB1A6    : #hx[178] = 0x6F78    : #hx[242] = 0x6D25
  439.     #hx[ 51] = 0x1F47    : #hx[115] = 0x049F    : #hx[179] = 0xF3FE    : #hx[243] = 0x0BEE
  440.     #hx[ 52] = 0x7C74    : #hx[116] = 0x8B30    : #hx[180] = 0x387B    : #hx[244] = 0xE76B
  441.     #hx[ 53] = 0xBF9D    : #hx[117] = 0xB545    : #hx[181] = 0xCCC2    : #hx[245] = 0x6751
  442.     #hx[ 54] = 0x7646    : #hx[118] = 0x48EC    : #hx[182] = 0x762C    : #hx[246] = 0x2A06
  443.     #hx[ 55] = 0xC9FF    : #hx[119] = 0xF885    : #hx[183] = 0x603E    : #hx[247] = 0x49E3
  444.     #hx[ 56] = 0x7944    : #hx[120] = 0x3985    : #hx[184] = 0x02F9    : #hx[248] = 0x9854
  445.     #hx[ 57] = 0x953D    : #hx[121] = 0x3D6A    : #hx[185] = 0x3F51    : #hx[249] = 0x11F4
  446.     #hx[ 58] = 0xE666    : #hx[122] = 0x6871    : #hx[186] = 0x6C2E    : #hx[250] = 0xA655
  447.     #hx[ 59] = 0xB2DA    : #hx[123] = 0x2F08    : #hx[187] = 0x0777    : #hx[251] = 0x742F
  448.     #hx[ 60] = 0x743C    : #hx[124] = 0x94DE    : #hx[188] = 0xE456    : #hx[252] = 0x8C19
  449.     #hx[ 61] = 0xDB99    : #hx[125] = 0x4CA5    : #hx[189] = 0x7AA0    : #hx[253] = 0xB74A
  450.     #hx[ 62] = 0x48BB    : #hx[126] = 0xD5EA    : #hx[190] = 0x0766    : #hx[254] = 0xD219
  451.     #hx[ 63] = 0xF794    : #hx[127] = 0xAD4C    : #hx[191] = 0x4882    : #hx[255] = 0x63DD
  452. '
  453. '
  454. ' dimension charset arrays - all have 256 entries, one for each byte/character value
  455. '
  456.     DIM #charsetSymbolFirst[255]
  457.     DIM #charsetSymbolInner[255]
  458.     DIM #charsetSymbolFinal[255]
  459.     DIM #charsetSymbol[255]
  460.     DIM #charsetUpper[255]
  461.     DIM #charsetLower[255]
  462.     DIM #charsetNumeric[255]
  463.     DIM #charsetUpperLower[255]
  464.     DIM #charsetUpperNumeric[255]
  465.     DIM #charsetLowerNumeric[255]
  466.     DIM #charsetUpperLowerNumeric[255]
  467.     DIM #charsetUpperToLower[255]
  468.     DIM #charsetLowerToUpper[255]
  469.     DIM #charsetVex[255]
  470.     DIM #charsetHexUpper[255]
  471.     DIM #charsetHexLower[255]
  472.     DIM #charsetHexUpperLower[255]
  473.     DIM #charsetHexUpperToLower[255]
  474.     DIM #charsetHexLowerToUpper[255]
  475.     DIM #charsetBackslash[255]
  476.     DIM #charsetBackslashByte[255]
  477.     DIM #charsetBackslashChar[255]
  478.     DIM #charsetNormalChar[255]
  479.     DIM #charsetOctal[255]
  480.     DIM #charsetPrintChar[255]
  481.     DIM #charsetSuffix[255]
  482.     DIM #charsetSpaceTab[255]
  483.     DIM #charsetWhitespace[255]
  484. '
  485. '
  486. ' ***********************************
  487. ' *****  #charsetSymbolFirst[]  *****  A-Z  a-z  (others 0)
  488. ' ***********************************
  489. '
  490.     FOR i = 0 TO 255
  491.         SELECT CASE TRUE
  492.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetSymbolFirst[i] = i
  493.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetSymbolFirst[i] = i
  494.             CASE  (i  = '_')                                    : #charsetSymbolFirst[i] = i
  495.             CASE ELSE                                                    : #charsetSymbolFirst[i] = 0
  496.         END SELECT
  497.     NEXT i
  498. '
  499. '
  500. ' ***********************************
  501. ' *****  #charsetSymbolInner[]  *****  A-Z  a-z  0-9  "_"  (others 0)
  502. ' ***********************************
  503. '
  504.     FOR i = 0 TO 255
  505.         SELECT CASE TRUE
  506.             CASE ((i >= '0') AND (i <= '9'))    : #charsetSymbolInner[i] = i
  507.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetSymbolInner[i] = i
  508.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetSymbolInner[i] = i
  509.             CASE  (i  = '_')                                    : #charsetSymbolInner[i] = i
  510.             CASE ELSE                                                    : #charsetSymbolInner[i] = 0
  511.         END SELECT
  512.     NEXT i
  513. '
  514. '
  515. ' ***********************************
  516. ' *****  #charsetSymbolFinal[]  *****  A-Z  a-z  0-9  "_"  (others 0)
  517. ' ***********************************
  518. '
  519.     FOR i = 0 TO 255
  520.         SELECT CASE TRUE
  521.             CASE ((i >= '0') AND (i <= '9'))    : #charsetSymbolFinal[i] = i
  522.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetSymbolFinal[i] = i
  523.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetSymbolFinal[i] = i
  524.             CASE  (i  = '_')                                    : #charsetSymbolFinal[i] = i
  525.             CASE ELSE                                                    : #charsetSymbolFinal[i] = 0
  526.         END SELECT
  527.     NEXT i
  528. '
  529. '
  530. ' ******************************
  531. ' *****  #charsetSymbol[]  *****  A-Z  a-z  0-9  "_"  (others 0)
  532. ' ******************************
  533. '
  534.     FOR i = 0 TO 255
  535.         SELECT CASE TRUE
  536.             CASE ((i >= '0') AND (i <= '9'))    : #charsetSymbol[i] = i
  537.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetSymbol[i] = i
  538.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetSymbol[i] = i
  539.             CASE  (i  = '_')                                    : #charsetSymbol[i] = i
  540.             CASE ELSE                                                    : #charsetSymbol[i] = 0
  541.         END SELECT
  542.     NEXT i
  543. '
  544. '
  545. ' *****************************
  546. ' *****  #charsetUpper[]  *****  A-Z  (others 0)
  547. ' *****************************
  548. '
  549.     FOR i = 0 TO 255
  550.         SELECT CASE TRUE
  551.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetUpper[i] = i
  552.             CASE ELSE                                                    : #charsetUpper[i] = 0
  553.         END SELECT
  554.     NEXT i
  555. '
  556. '
  557. ' *****************************
  558. ' *****  #charsetLower[]  *****  a-z  (others 0)
  559. ' *****************************
  560. '
  561.     FOR i = 0 TO 255
  562.         SELECT CASE TRUE
  563.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetLower[i] = i
  564.             CASE ELSE                                                    : #charsetLower[i] = 0
  565.         END SELECT
  566.     NEXT i
  567. '
  568. '
  569. ' *******************************
  570. ' *****  #charsetNumeric[]  *****  0-9  (others 0)
  571. ' *******************************
  572. '
  573.     FOR i = 0 TO 255
  574.         SELECT CASE TRUE
  575.             CASE ((i >= '0') AND (i <= '9'))    : #charsetNumeric[i] = i
  576.             CASE ELSE                                                    : #charsetNumeric[i] = 0
  577.         END SELECT
  578.     NEXT i
  579. '
  580. '
  581. ' **********************************
  582. ' *****  #charsetUpperLower[]  *****  A-Z  a-z  (others 0)
  583. ' **********************************
  584. '
  585.     FOR i = 0 TO 255
  586.         SELECT CASE TRUE
  587.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetUpperLower[i] = i
  588.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetUpperLower[i] = i
  589.             CASE ELSE                                                    : #charsetUpperLower[i] = 0
  590.         END SELECT
  591.     NEXT i
  592. '
  593. '
  594. ' ************************************
  595. ' *****  #charsetUpperNumeric[]  *****  A-Z  0-9  (others 0)
  596. ' ************************************
  597. '
  598.     FOR i = 0 TO 255
  599.         SELECT CASE TRUE
  600.             CASE ((i >= '0') AND (i <= '9'))    : #charsetUpperNumeric[i] = i
  601.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetUpperNumeric[i] = i
  602.             CASE ELSE                                                    : #charsetUpperNumeric[i] = 0
  603.         END SELECT
  604.     NEXT i
  605. '
  606. '
  607. ' ************************************
  608. ' *****  #charsetLowerNumeric[]  *****  a-z  0-9  (others 0)
  609. ' ************************************
  610. '
  611.     FOR i = 0 TO 255
  612.         SELECT CASE TRUE
  613.             CASE ((i >= '0') AND (i <= '9'))    : #charsetLowerNumeric[i] = i
  614.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetLowerNumeric[i] = i
  615.             CASE ELSE                                                    : #charsetLowerNumeric[i] = 0
  616.         END SELECT
  617.     NEXT i
  618. '
  619. '
  620. ' *****************************************
  621. ' *****  #charsetUpperLowerNumeric[]  *****  A-Z  a-z  0-9  (others 0)
  622. ' *****************************************
  623. '
  624.     FOR i = 0 TO 255
  625.         SELECT CASE TRUE
  626.             CASE ((i >= '0') AND (i <= '9'))    : #charsetUpperLowerNumeric[i] = i
  627.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetUpperLowerNumeric[i] = i
  628.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetUpperLowerNumeric[i] = i
  629.             CASE ELSE                                                    : #charsetUpperLowerNumeric[i] = 0
  630.         END SELECT
  631.     NEXT i
  632. '
  633. '
  634. ' ************************************
  635. ' *****  #charsetUpperToLower[]  *****  A-Z  ==>>  a-z  (others unchanged)
  636. ' ************************************
  637. '
  638.     FOR i = 0 TO 255
  639.         SELECT CASE TRUE
  640.             CASE ((i >= 'A') AND (i <= 'Z'))    : #charsetUpperToLower[i] = i + 32
  641.             CASE ELSE                                                    : #charsetUpperToLower[i] = i
  642.         END SELECT
  643.     NEXT i
  644. '
  645. '
  646. ' ************************************
  647. ' *****  #charsetLowerToUpper[]  *****  a-z  ==>>  A-Z  (others unchanged)
  648. ' ************************************
  649. '
  650.     FOR i = 0 TO 255
  651.         SELECT CASE TRUE
  652.             CASE ((i >= 'a') AND (i <= 'z'))    : #charsetLowerToUpper[i] = i - 32
  653.             CASE ELSE                                                    : #charsetLowerToUpper[i] = i
  654.         END SELECT
  655.     NEXT i
  656. '
  657. '
  658. ' ***************************
  659. ' *****  #charsetVex[]  *****  0-9  A-V  (others 0)
  660. ' ***************************
  661. '
  662.     FOR i = 0 TO 255
  663.         SELECT CASE TRUE
  664.             CASE ((i >= '0') AND (i <= '9'))    : #charsetVex[i] = i
  665.             CASE ((i >= 'A') AND (i <= 'V'))    : #charsetVex[i] = i
  666.             CASE ELSE                                                    : #charsetVex[i] = 0
  667.         END SELECT
  668.     NEXT i
  669. '
  670. '
  671. ' *****************************
  672. ' *****  #charsetOctal[]  *****  0-7
  673. ' *****************************
  674. '
  675.     FOR i = 0 TO 255
  676.         SELECT CASE TRUE
  677.             CASE ((i >= '0') AND (i <= '7'))    : #charsetHexUpper[i] = i
  678.             CASE ELSE                                                    : #charsetHexUpper[i] = 0
  679.         END SELECT
  680.     NEXT i
  681. '
  682. '
  683. ' ********************************
  684. ' *****  #charsetHexUpper[]  *****  0-9  A-F  (others 0)
  685. ' ********************************
  686. '
  687.     FOR i = 0 TO 255
  688.         SELECT CASE TRUE
  689.             CASE ((i >= '0') AND (i <= '9'))    : #charsetHexUpper[i] = i
  690.             CASE ((i >= 'A') AND (i <= 'F'))    : #charsetHexUpper[i] = i
  691.             CASE ELSE                                                    : #charsetHexUpper[i] = 0
  692.         END SELECT
  693.     NEXT i
  694. '
  695. '
  696. ' ********************************
  697. ' *****  #charsetHexLower[]  *****  0-9  a-f  (others 0)
  698. ' ********************************
  699. '
  700.     FOR i = 0 TO 255
  701.         SELECT CASE TRUE
  702.             CASE ((i >= '0') AND (i <= '9'))    : #charsetHexLower[i] = i
  703.             CASE ((i >= 'a') AND (i <= 'f'))    : #charsetHexLower[i] = i
  704.             CASE ELSE                                                    : #charsetHexLower[i] = 0
  705.         END SELECT
  706.     NEXT i
  707. '
  708. '
  709. ' *************************************
  710. ' *****  #charsetHexUpperLower[]  *****  0-9  A-F  a-f  (others 0)
  711. ' *************************************
  712. '
  713.     FOR i = 0 TO 255
  714.         SELECT CASE TRUE
  715.             CASE ((i >= '0') AND (i <= '9'))    : #charsetHexUpperLower[i] = i
  716.             CASE ((i >= 'A') AND (i <= 'F'))    : #charsetHexUpperLower[i] = i
  717.             CASE ((i >= 'a') AND (i <= 'f'))    : #charsetHexUpperLower[i] = i
  718.             CASE ELSE                                                    : #charsetHexUpperLower[i] = 0
  719.         END SELECT
  720.     NEXT i
  721. '
  722. '
  723. ' ***************************************  0-9
  724. ' *****  #charsetHexUpperToLower[]  *****  A-F  ==>>  a-f  (others 0)
  725. ' ***************************************  a-f
  726. '
  727.     FOR i = 0 TO 255
  728.         SELECT CASE TRUE
  729.             CASE ((i >= '0') AND (i <= '9'))    : #charsetHexUpperToLower[i] = i
  730.             CASE ((i >= 'A') AND (i <= 'F'))    : #charsetHexUpperToLower[i] = i + 32
  731.             CASE ((i >= 'a') AND (i <= 'f'))    : #charsetHexUpperToLower[i] = i
  732.             CASE ELSE                                                    : #charsetHexUpperToLower[i] = 0
  733.         END SELECT
  734.     NEXT i
  735. '
  736. '
  737. ' ***************************************  0-9
  738. ' *****  #charsetHexLowerToUpper[]  *****  a-f  ==>>  A-F  (others 0)
  739. ' ***************************************  A-F
  740. '
  741.     FOR i = 0 TO 255
  742.         SELECT CASE TRUE
  743.             CASE ((i >= '0') AND (i <= '9'))    : #charsetHexLowerToUpper[i] = i
  744.             CASE ((i >= 'A') AND (i <= 'F'))    : #charsetHexLowerToUpper[i] = i
  745.             CASE ((i >= 'a') AND (i <= 'f'))    : #charsetHexLowerToUpper[i] = i - 32
  746.             CASE ELSE                                                    : #charsetHexLowerToUpper[i] = 0
  747.         END SELECT
  748.     NEXT i
  749. '
  750. '
  751. ' *********************************  \a  \b  \d  \f  \n  \r  \v  \\  \"  \z
  752. ' *****  #charsetBackslash[]  *****  \0 - \V
  753. ' *********************************  (others unchanged)
  754. '
  755. ' Convert character following a \ into the proper binary value
  756. ' For all characters without special binary values, return the character
  757. '
  758.     offset = 10 - 'A'
  759.     FOR i = 0 TO 255
  760.         SELECT CASE TRUE
  761.             CASE ((i >= '0') AND (i <= '9'))    : #charsetBackslash[i] = i - '0'
  762.             CASE ((i >= 'A') AND (i <= 'V'))    : #charsetBackslash[i] = i + offset
  763.             CASE ELSE                                                    : #charsetBackslash[i] = i
  764.         END SELECT
  765.     NEXT i
  766. '
  767.     FOR i = 0 TO 255
  768.         SELECT CASE i
  769.             CASE '\\'    : #charsetBackslash[i] = 0x5C        ' backslash
  770.             CASE '"'    : #charsetBackslash[i] = 0x22        ' double-quote
  771.             CASE 'a'    : #charsetBackslash[i] = 0x07        ' alarm (bell)
  772.             CASE 'b'    : #charsetBackslash[i] = 0x08        ' backspace
  773.             CASE 'd'    : #charsetBackslash[i] = 0x7F        ' delete
  774.             CASE 'e'    : #charsetBackslash[i] = 0x1B        ' escape
  775.             CASE 'f'    : #charsetBackslash[i] = 0x0C        ' form-feed
  776.             CASE 'n'    : #charsetBackslash[i] = 0x0A        ' newline
  777.             CASE 'r'    : #charsetBackslash[i] = 0x0D        ' return
  778.             CASE 't'    : #charsetBackslash[i] = 0x09        ' tab
  779.             CASE 'v'    : #charsetBackslash[i] = 0x0B        ' vertical-tab
  780.             CASE 'z'    : #charsetBackslash[i] = 0xFF        ' finale  (highest UBYTE)
  781.         END SELECT
  782.     NEXT i
  783. '
  784. '
  785. ' *************************************  \a  \b  \d  \e  \f  \n  \r  \t  \v
  786. ' *****  #charsetBackslashByte[]  *****  \\  \"
  787. ' *************************************
  788. '
  789. ' Return printable character intended to follow \ backslash character for
  790. ' SIMPLE (only simple) 1 character backslash codes, as understood by dumb
  791. ' assemblers, for example.  Otherwise, return zero.
  792. '
  793.     FOR i = 0 TO 255
  794.         SELECT CASE i
  795.             CASE 0x5C    : #charsetBackslashByte[i] = '\\'    ' backslash
  796.             CASE 0x22    : #charsetBackslashByte[i] = '"'        ' double-quote
  797.             CASE 0x07    : #charsetBackslashByte[i] = 'a'        ' alarm (bell)
  798.             CASE 0x08    : #charsetBackslashByte[i] = 'b'        ' backspace
  799.             CASE 0x7F    : #charsetBackslashByte[i] = 'd'        ' delete
  800.             CASE 0x1B    : #charsetBackslashByte[i] = 'e'        ' escape
  801.             CASE 0x0C    : #charsetBackslashByte[i] = 'f'        ' form-feed
  802.             CASE 0x0A    : #charsetBackslashByte[i] = 'n'        ' newline
  803.             CASE 0x0D    : #charsetBackslashByte[i] = 'r'        ' return
  804.             CASE 0x09    : #charsetBackslashByte[i] = 't'        ' tab
  805.             CASE 0x0B    : #charsetBackslashByte[i] = 'v'        ' vertical-tab
  806.             CASE 0x00    : #charsetBackslashByte[i] = '0'        ' null
  807.             CASE ELSE    : #charsetBackslashByte[i] = 0            ' non-simple backslash
  808.         END SELECT
  809.     NEXT i
  810. '
  811. '
  812. ' *************************************  \a  \b  \d  \e  \f  \n  \r  \t  \v
  813. ' *****  #charsetBackslashChar[]  *****  \\  \"
  814. ' *************************************
  815. '
  816. ' Return printable character intended to follow \ backslash character
  817. ' Return bytes that are normal, printable, non-backslash characters
  818. '
  819.     FOR i = 0 TO 255
  820.         SELECT CASE i
  821.             CASE 0x5C    : #charsetBackslashChar[i] = '\\'    ' backslash
  822.             CASE 0x22    : #charsetBackslashChar[i] = '"'        ' double-quote
  823.             CASE 0x07    : #charsetBackslashChar[i] = 'a'        ' alarm (bell)
  824.             CASE 0x08    : #charsetBackslashChar[i] = 'b'        ' backspace
  825.             CASE 0x7F    : #charsetBackslashChar[i] = 'd'        ' delete
  826.             CASE 0x1B    : #charsetBackslashChar[i] = 'e'        ' escape
  827.             CASE 0x0C    : #charsetBackslashChar[i] = 'f'        ' form-feed
  828.             CASE 0x0A    : #charsetBackslashChar[i] = 'n'        ' newline
  829.             CASE 0x0D    : #charsetBackslashChar[i] = 'r'        ' return
  830.             CASE 0x09    : #charsetBackslashChar[i] = 't'        ' tab
  831.             CASE 0x0B    : #charsetBackslashChar[i] = 'v'        ' vertical-tab
  832.             CASE ELSE    : #charsetBackslashChar[i] = 0            ' not a backslash char
  833.         END SELECT
  834.     NEXT i
  835. '
  836. '
  837. ' **********************************  0x00 - 0x1F  ===>>  0
  838. ' *****  #charsetNormalChar[]  *****  0x7F - 0xFF  ===>>  0  (others unchanged)
  839. ' **********************************   \  and  "   ===>>  0
  840. '
  841. ' Normal printable characters = the character, all others = 0
  842. ' NOTE:  tab, newline, etc... not considered normal printable characters
  843. ' NOTE:  backslash not considered normal printable character (need \\)
  844. ' NOTE:  double-quote not considered normal printable character (need \")
  845. '
  846.     FOR i = 0 TO 255
  847.         SELECT CASE TRUE
  848.             CASE (i <=  31)    : #charsetNormalChar[i] = 0
  849.             CASE (i >= 127)    : #charsetNormalChar[i] = 0
  850.             CASE (i = '\\')    : #charsetNormalChar[i] = 0
  851.             CASE (i = '"')    : #charsetNormalChar[i] = 0
  852.             CASE ELSE                : #charsetNormalChar[i] = i
  853.         END SELECT
  854.     NEXT i
  855. '
  856. '
  857. ' *********************************  0x00 - 0x1F  ===>>  0
  858. ' *****  #charsetPrintChar[]  *****  0x7F - 0xFF  ===>>  0
  859. ' *********************************  (others unchanged)
  860. '
  861. ' Printable characters = the character, all others = 0
  862. ' NOTE:  tab, newline, etc... not considered normal printable characters
  863. ' NOTE:  backslash is a printable character
  864. ' NOTE:  double-quote is a printable character
  865. '
  866.     FOR i = 0 TO 255
  867.         SELECT CASE TRUE
  868.             CASE (i <=  31)    : #charsetPrintChar[i] = 0
  869.             CASE (i >= 127)    : #charsetPrintChar[i] = 0
  870.             CASE ELSE                : #charsetPrintChar[i] = i
  871.         END SELECT
  872.     NEXT i
  873. '
  874. '
  875. ' ******************************
  876. ' *****  #charsetSuffix[]  *****  valid type suffixes
  877. ' ******************************
  878. '
  879.     #charsetSuffix['%']    = '%'
  880.     #charsetSuffix['&']    = '&'
  881.     #charsetSuffix['!']    = '!'
  882.     #charsetSuffix['#']    = '#'
  883.     #charsetSuffix['$']    = '$'
  884. '
  885. '
  886. ' ********************************
  887. ' *****  #charsetSpaceTab[]  *****  only <space> and <tab> are true
  888. ' ********************************
  889. '
  890.     #charsetSpaceTab[0x09]    = 0x09        ' <tab>        = '\t'
  891.     #charsetSpaceTab[0x20]    = 0x20        ' <space>    = ' '
  892. '
  893. '
  894. ' **********************************
  895. ' *****  #charsetWhitespace[]  *****  all whitespace characters (space, tab, garbage)
  896. ' **********************************
  897. '
  898.     FOR i = 0 TO 255
  899.         SELECT CASE TRUE
  900.             CASE (i <= 0x20)    : #charsetWhitespace[i] = i        ' from 0x00 to 0x20 (tab, space, trash)
  901.             CASE (i >= 0x80)    : #charsetWhitespace[i] = i        ' from 0x80 to 0xFF (unprintable trash)
  902.         END SELECT
  903.     NEXT i
  904. END FUNCTION
  905. '
  906. '
  907. ' #######################################
  908. ' #####  InitializeQBasicTokens ()  #####
  909. ' #######################################
  910. '
  911. FUNCTION  InitializeQBasicTokens ()
  912. '
  913. ' define some shorthand variables
  914. '
  915. ' common types
  916. '
  917.     t0 = 0
  918.     tw = $$TYPE_SSHORT        ' word
  919.     ti = $$TYPE_XLONG            ' integer
  920.     tg = $$TYPE_GIANT            ' giant-integer
  921.     tf = $$TYPE_DOUBLE        ' floating-point
  922.     ts = $$TYPE_STRING        ' nominal string
  923. '
  924. ' common kinds
  925. '
  926.     k0 = 0
  927.     ks = $$KIND_QBASIC | $$KIND_STATEMENT
  928.     ki = $$KIND_QBASIC | $$KIND_INTRINSIC
  929.     ko = $$KIND_QBASIC | $$KIND_OPERATOR
  930.     kk = $$KIND_QBASIC | $$KIND_KEYWORD
  931.     kt = $$KIND_QBASIC | $$KIND_TYPE
  932.     kl = $$KIND_QBASIC | $$KIND_LITERAL
  933.     kf = $$KIND_QBASIC | $$KIND_FUNCTION
  934.     ky = $$KIND_QBASIC | $$KIND_SYMBOL
  935.     kv = $$KIND_QBASIC | $$KIND_VARIABLE
  936.     ka = $$KIND_QBASIC | $$KIND_ARRAY
  937.     kc = $$KIND_QBASIC | $$KIND_COMPOSITE
  938.     ke = $$KIND_QBASIC | $$KIND_ELEMENT
  939.     kh = $$KIND_QBASIC | $$KIND_CHARACTER
  940.     kq = $$KIND_QBASIC
  941. '
  942. ' common scopes
  943. '
  944.     s0 = 0
  945.     sa = $$SCOPE_AUTO
  946.     sl = $$SCOPE_STATIC
  947.     ss = $$SCOPE_SHARED
  948.     se = $$SCOPE_EXTERNAL
  949. '
  950.     q0 = 0
  951.     x0 = 0
  952. '
  953. '
  954. ' token_number     = AddKeyword (translate, function, scope, kind, rtype, arg0, arg1, arg2, string$)
  955. '
  956.     #qatoken         = #ntoken + 1
  957.     #Q_ABS           = AddKeyword (#X_ABS        , f0, s0, ki, tf, tf, t0, t0, "ABS")
  958.     #Q_ABSOLUTE      = AddKeyword (            x0, f0, s0, ki, tf, tf, t0, t0, "ABSOLUTE")
  959.     #Q_ACCESS        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ACCESS")
  960.     #Q_ALIAS         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ALIAS")
  961.     #Q_AND           = AddKeyword (#X_AND        , f0, s0, ko, t0, t0, t0, t0, "AND")
  962.     #Q_ANY           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ANY")
  963.     #Q_APPEND        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "APPEND")
  964.     #Q_AS            = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "AS")
  965.     #Q_ASC           = AddKeyword (#X_ASC        , f0, s0, ki, t0, t0, t0, t0, "ASC")
  966.     #Q_ATN           = AddKeyword (#X_ATAN       , f0, s0, ki, t0, t0, t0, t0, "ATN")
  967.     #Q_BASE          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "BASE")
  968.     #Q_BEEP          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "BEEP")
  969.     #Q_BINARY        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "BINARY")
  970.     #Q_BLOAD         = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "BLOAD")
  971.     #Q_BSAVE         = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "BSAVE")
  972.     #Q_BYVAL         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "BYVAL")
  973.     #Q_CALL          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CALL")
  974.     #Q_CALLS         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CALLS")
  975.     #Q_CASE          = AddKeyword (#X_CASE       , f0, s0, ks, t0, t0, t0, t0, "CASE")
  976.     #Q_CCUR          = AddKeyword (#X_GIANT      , f0, s0, ki, t0, t0, t0, t0, "CCUR")
  977.     #Q_CDBL          = AddKeyword (#X_DOUBLE     , f0, s0, ki, t0, t0, t0, t0, "CDBL")
  978.     #Q_CDECL         = AddKeyword (#X_CFUNCTION  , f0, s0, k0, t0, t0, t0, t0, "CDECL")
  979.     #Q_CHAIN         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CHAIN")
  980.     #Q_CHDIR         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CHDIR")
  981.     #Q_CHDRIVE       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CHDRIVE")
  982.     #Q_CHR_D         = AddKeyword (#X_CHR_D      , f0, s0, ki, t0, t0, t0, t0, "CHR$")
  983.     #Q_CINT          = AddKeyword (#X_SSHORT     , f0, s0, ki, t0, t0, t0, t0, "CINT")
  984.     #Q_CIRCLE        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CIRCLE")
  985.     #Q_CLEAR         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CLEAR")
  986.     #Q_CLNG          = AddKeyword (#X_SLONG      , f0, s0, ki, t0, t0, t0, t0, "CLNG")
  987.     #Q_CLOSE         = AddKeyword (#X_CLOSE      , f0, s0, k0, t0, t0, t0, t0, "CLOSE")
  988.     #Q_CLS           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CLS")
  989.     #Q_COLOR         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "COLOR")
  990.     #Q_COM           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "COM")
  991.     #Q_COMMAND_D     = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "COMMAND$")
  992.     #Q_COMMON        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "COMMON")
  993.     #Q_CONST         = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "CONST")
  994.     #Q_COS           = AddKeyword (#X_COS        , f0, s0, ki, t0, t0, t0, t0, "COS")
  995.     #Q_CSNG          = AddKeyword (#X_SINGLE     , f0, s0, ki, t0, t0, t0, t0, "CSNG")
  996.     #Q_CSRLIN        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CSRLIN")
  997.     #Q_CURDIR_D      = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "CURDIR$")
  998.     #Q_CURRENCY      = AddKeyword (#X_GIANT      , f0, s0, k0, t0, t0, t0, t0, "CURRENCY")
  999.     #Q_CVC           = AddKeyword (#X_GIANT      , f0, s0, ki, t0, t0, t0, t0, "CVC")
  1000.     #Q_CVD           = AddKeyword (#X_DOUBLE     , f0, s0, ki, t0, t0, t0, t0, "CVD")
  1001.     #Q_CVI           = AddKeyword (#X_SSHORT     , f0, s0, ki, t0, t0, t0, t0, "CVI")
  1002.     #Q_CVL           = AddKeyword (#X_SLONG      , f0, s0, ki, t0, t0, t0, t0, "CVL")
  1003.     #Q_CVS           = AddKeyword (#X_SINGLE     , f0, s0, ki, t0, t0, t0, t0, "CVS")
  1004.     #Q_CVSMBF        = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "CVSMBF")
  1005.     #Q_DATA          = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "DATA")
  1006.     #Q_DATE_D        = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "DATE$")
  1007.     #Q_DECLARE       = AddKeyword (#X_DECLARE    , f0, s0, ks, t0, t0, t0, t0, "DECLARE")
  1008.     #Q_DEF           = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "DEF")
  1009.     #Q_DEFCUR        = AddKeyword (#X_GIANT      , f0, s0, ks, t0, t0, t0, t0, "DEFCUR")
  1010.     #Q_DEFDBL        = AddKeyword (#X_DOUBLE     , f0, s0, ks, t0, t0, t0, t0, "DEFDBL")
  1011.     #Q_DEFINT        = AddKeyword (#X_SSHORT     , f0, s0, ks, t0, t0, t0, t0, "DEFINT")
  1012.     #Q_DEFLNG        = AddKeyword (#X_SLONG      , f0, s0, ks, t0, t0, t0, t0, "DEFLNG")
  1013.     #Q_DEFSNG        = AddKeyword (#X_SINGLE     , f0, s0, ks, t0, t0, t0, t0, "DEFSNG")
  1014.     #Q_DEFSTR        = AddKeyword (#X_STRING     , f0, s0, ks, t0, t0, t0, t0, "DEFSTR")
  1015.     #Q_DELETE        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "DELETE")
  1016.     #Q_DIM           = AddKeyword (#X_DIM        , f0, s0, ks, t0, t0, t0, t0, "DIM")
  1017.     #Q_DIR_D         = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "DIR$")
  1018.     #Q_DO            = AddKeyword (#X_DO         , f0, s0, ks, t0, t0, t0, t0, "DO")
  1019.     #Q_DOUBLE        = AddKeyword (#X_DOUBLE     , f0, s0, k0, t0, t0, t0, t0, "DOUBLE")
  1020.     #Q_DRAW          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "DRAW")
  1021.     #Q_DYNAMIC       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "DYNAMIC")
  1022.     #Q_ELSE          = AddKeyword (#X_ELSE       , f0, s0, ks, t0, t0, t0, t0, "ELSE")
  1023.     #Q_ELSEIF        = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "ELSEIF")
  1024.     #Q_END           = AddKeyword (#X_END        , f0, s0, ks, t0, t0, t0, t0, "END")
  1025.     #Q_ENDIF         = AddKeyword (#X_ENDIF      , f0, s0, ks, t0, t0, t0, t0, "ENDIF")
  1026.     #Q_ENVIRON       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ENVIRON")
  1027.     #Q_ENVIRON_D     = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ENVIRON$")
  1028.     #Q_EOF           = AddKeyword (#X_EOF        , f0, s0, ki, t0, t0, t0, t0, "EOF")
  1029.     #Q_EQV           = AddKeyword (            x0, f0, s0, ko, t0, t0, t0, t0, "EQV")
  1030.     #Q_ERASE         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ERASE")
  1031.     #Q_ERDEV         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ERDEV")
  1032.     #Q_ERDEV_D       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ERDEV$")
  1033.     #Q_ERL           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ERL")
  1034.     #Q_ERR           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ERR")
  1035.     #Q_ERROR         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "ERROR")
  1036.     #Q_EVENT         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "EVENT")
  1037.     #Q_EXIT          = AddKeyword (#X_EXIT       , f0, s0, ks, t0, t0, t0, t0, "EXIT")
  1038.     #Q_EXP           = AddKeyword (#X_EXP        , f0, s0, ki, t0, t0, t0, t0, "EXP")
  1039.     #Q_FIELD         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "FIELD")
  1040.     #Q_FILEATTR      = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "FILEATTR")
  1041.     #Q_FILES         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "FILES")
  1042.     #Q_FIX           = AddKeyword (#X_FIX        , f0, s0, ki, t0, t0, t0, t0, "FIX")
  1043.     #Q_FN            = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "FN")
  1044.     #Q_FOR           = AddKeyword (#X_FOR        , f0, s0, ks, t0, t0, t0, t0, "FOR")
  1045.     #Q_FRE           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "FRE")
  1046.     #Q_FREEFILE      = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "FREEFILE")
  1047.     #Q_FUNCTION      = AddKeyword (#X_FUNCTION   , f0, s0, ks, t0, t0, t0, t0, "FUNCTION")
  1048.     #Q_GET           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "GET")
  1049.     #Q_GOSUB         = AddKeyword (#X_GOSUB      , f0, s0, ks, t0, t0, t0, t0, "GOSUB")
  1050.     #Q_GOTO          = AddKeyword (#X_GOTO       , f0, s0, ks, t0, t0, t0, t0, "GOTO")
  1051.     #Q_HEX_D         = AddKeyword (#X_HEX_D      , f0, s0, ki, t0, t0, t0, t0, "HEX$")
  1052.     #Q_IF            = AddKeyword (#X_IF         , f0, s0, ks, t0, t0, t0, t0, "IF")
  1053.     #Q_IMP           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "IMP")
  1054.     #Q_INCLUDE       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "INCLUDE")
  1055.     #Q_INKEY_D       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "INKEY$")
  1056.     #Q_INP           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "INP")
  1057.     #Q_INPUT         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "INPUT")
  1058.     #Q_INPUT_D       = AddKeyword (#X_INLINE_D   , f0, s0, k0, t0, t0, t0, t0, "INPUT$")
  1059.     #Q_INSTR         = AddKeyword (#X_INSTR      , f0, s0, ki, t0, t0, t0, t0, "INSTR")
  1060.     #Q_INT           = AddKeyword (#X_INT        , f0, s0, ki, t0, t0, t0, t0, "INT")
  1061.     #Q_INTEGER       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "INTEGER")
  1062.     #Q_INTERRUPT     = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "INTERRUPT")
  1063.     #Q_IOCTL         = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "IOCTL")
  1064.     #Q_IOCTL_D       = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "IOCTL$")
  1065.     #Q_IS            = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "IS")
  1066.     #Q_KEY           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "KEY")
  1067.     #Q_KILL          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "KILL")
  1068.     #Q_LBOUND        = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "LBOUND")
  1069.     #Q_LCASE_D       = AddKeyword (#X_LCASE_D    , f0, s0, ki, t0, t0, t0, t0, "LCASE$")
  1070.     #Q_LEFT_D        = AddKeyword (#X_LEFT_D     , f0, s0, ki, t0, t0, t0, t0, "LEFT$")
  1071.     #Q_LEN           = AddKeyword (#X_LEN        , f0, s0, ki, t0, t0, t0, t0, "LEN")
  1072.     #Q_LET           = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "LET")
  1073.     #Q_LINE          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "LINE")
  1074.     #Q_LIST          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "LIST")
  1075.     #Q_LOC           = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "LOC")
  1076.     #Q_LOCAL         = AddKeyword (#X_AUTO       , f0, s0, k0, t0, t0, t0, t0, "LOCAL")
  1077.     #Q_LOCATE        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "LOCATE")
  1078.     #Q_LOCK          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "LOCK")
  1079.     #Q_LOF           = AddKeyword (#X_LOF        , f0, s0, ki, t0, t0, t0, t0, "LOF")
  1080.     #Q_LOG           = AddKeyword (#X_LOG        , f0, s0, ki, t0, t0, t0, t0, "LOG")
  1081.     #Q_LONG          = AddKeyword (#X_SLONG      , f0, s0, k0, t0, t0, t0, t0, "LONG")
  1082.     #Q_LOOP          = AddKeyword (#X_LOOP       , f0, s0, ks, t0, t0, t0, t0, "LOOP")
  1083.     #Q_LPOS          = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "LPOS")
  1084.     #Q_LPRINT        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "LPRINT")
  1085.     #Q_LSET          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "LSET")
  1086.     #Q_LTRIM_D       = AddKeyword (#X_LTRIM_D    , f0, s0, ki, t0, t0, t0, t0, "LTRIM$")
  1087.     #Q_MID_D         = AddKeyword (#X_MID_D      , f0, s0, ki, t0, t0, t0, t0, "MID$")
  1088.     #Q_MKC_D         = AddKeyword (#X_STRING_D   , f0, s0, ki, t0, t0, t0, t0, "MKC$")
  1089.     #Q_MKDIR         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "MKDIR")
  1090.     #Q_MKDMBF_D      = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "MKDMBF$")
  1091.     #Q_MKD_D         = AddKeyword (#X_STRING_D   , f0, s0, ki, t0, t0, t0, t0, "MKD$")
  1092.     #Q_MKI_D         = AddKeyword (#X_STRING_D   , f0, s0, ki, t0, t0, t0, t0, "MKI$")
  1093.     #Q_MKL_D         = AddKeyword (#X_STRING_D   , f0, s0, ki, t0, t0, t0, t0, "MKL$")
  1094.     #Q_MKS_D         = AddKeyword (#X_STRING_D   , f0, s0, ki, t0, t0, t0, t0, "MKS$")
  1095.     #Q_MKSMBF_D      = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "MKSMBF$")
  1096.     #Q_MOD           = AddKeyword (#X_MOD        , f0, s0, ko, t0, t0, t0, t0, "MOD")
  1097.     #Q_NAME          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "NAME")
  1098.     #Q_NEXT          = AddKeyword (#X_NEXT       , f0, s0, ks, t0, t0, t0, t0, "NEXT")
  1099.     #Q_NOT           = AddKeyword (#X_NOT        , f0, s0, ko, t0, t0, t0, t0, "NOT")
  1100.     #Q_OCT_D         = AddKeyword (#X_OCT_D      , f0, s0, ki, t0, t0, t0, t0, "OCT$")
  1101.     #Q_OFF           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "OFF")
  1102.     #Q_ON            = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "ON")
  1103.     #Q_OPEN          = AddKeyword (#X_OPEN       , f0, s0, k0, t0, t0, t0, t0, "OPEN")
  1104.     #Q_OPTION        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "OPTION")
  1105.     #Q_OR            = AddKeyword (#X_OR         , f0, s0, ko, t0, t0, t0, t0, "OR")
  1106.     #Q_OUT           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "OUT")
  1107.     #Q_OUTPUT        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "OUTPUT")
  1108.     #Q_PAINT         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PAINT")
  1109.     #Q_PALETTE       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PALETTE")
  1110.     #Q_PCOPY         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PCOPY")
  1111.     #Q_PEEK          = AddKeyword (#X_UBYTE_AT   , f0, s0, ki, t0, t0, t0, t0, "PEEK")
  1112.     #Q_PEN           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PEN")
  1113.     #Q_PLAY          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PLAY")
  1114.     #Q_PMAP          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PMAP")
  1115.     #Q_POINT         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "POINT")
  1116.     #Q_POKE          = AddKeyword (#X_UBYTE_AT   , f0, s0, ks, t0, t0, t0, t0, "POKE")
  1117.     #Q_POS           = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "POS")
  1118.     #Q_PRESET        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PRESET")
  1119.     #Q_PRINT         = AddKeyword (#X_PRINT      , f0, s0, ks, t0, t0, t0, t0, "PRINT")
  1120.     #Q_PSET          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PSET")
  1121.     #Q_PUT           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "PUT")
  1122.     #Q_RANDOM        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "RANDOM")
  1123.     #Q_RANDOMIZE     = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "RANDOMIZE")
  1124.     #Q_READ          = AddKeyword (#X_READ       , f0, s0, ks, t0, t0, t0, t0, "READ")
  1125.     #Q_REDIM         = AddKeyword (#X_REDIM      , f0, s0, ks, t0, t0, t0, t0, "REDIM")
  1126.     #Q_REM           = AddKeyword (#X_REMARK     , f0, s0, ks, t0, t0, t0, t0, "REM")
  1127.     #Q_RESET         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "RESET")
  1128.     #Q_RESTORE       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "RESTORE")
  1129.     #Q_RESUME        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "RESUME")
  1130.     #Q_RETURN        = AddKeyword (            x0, f0, s0, ks, t0, t0, t0, t0, "RETURN")
  1131.     #Q_RIGHT_D       = AddKeyword (#X_RIGHT_D    , f0, s0, ki, t0, t0, t0, t0, "RIGHT$")
  1132.     #Q_RMDIR         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "RMDIR")
  1133.     #Q_RND           = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "RND")
  1134.     #Q_RSET          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "RSET")
  1135.     #Q_RTRIM_D       = AddKeyword (#X_RTRIM_D    , f0, s0, ki, t0, t0, t0, t0, "RTRIM$")
  1136.     #Q_RUN           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "RUN")
  1137.     #Q_SADD          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SADD")
  1138.     #Q_SCREEN        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SCREEN")
  1139.     #Q_SEEK          = AddKeyword (#X_SEEK       , f0, s0, ki, t0, t0, t0, t0, "SEEK")
  1140.     #Q_SEG           = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SEG")
  1141.     #Q_SELECT        = AddKeyword (#X_SELECT     , f0, s0, ks, t0, t0, t0, t0, "SELECT")
  1142.     #Q_SETMEM        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SETMEM")
  1143.     #Q_SGN           = AddKeyword (#X_SGN        , f0, s0, ki, t0, t0, t0, t0, "SGN")
  1144.     #Q_SHARED        = AddKeyword (#X_SHARED     , f0, s0, ks, t0, t0, t0, t0, "SHARED")
  1145.     #Q_SHELL         = AddKeyword (#X_SHELL      , f0, s0, k0, t0, t0, t0, t0, "SHELL")
  1146.     #Q_SIGNAL        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SIGNAL")
  1147.     #Q_SIN           = AddKeyword (#X_SIN        , f0, s0, ki, t0, t0, t0, t0, "SIN")
  1148.     #Q_SINGLE        = AddKeyword (#X_SINGLE     , f0, s0, ks, t0, t0, t0, t0, "SINGLE")
  1149.     #Q_SLEEP         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SLEEP")
  1150.     #Q_SOUND         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SOUND")
  1151.     #Q_SPACE_D       = AddKeyword (#X_SPACE_D    , f0, s0, ki, t0, t0, t0, t0, "SPACE$")
  1152.     #Q_SPC           = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "SPC")
  1153.     #Q_SQR           = AddKeyword (#X_SQRT       , f0, s0, ki, t0, t0, t0, t0, "SQR")
  1154.     #Q_SSEG          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SSEG")
  1155.     #Q_SSEGADD       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SSEGADD")
  1156.     #Q_STACK         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "STACK")
  1157.     #Q_STATIC        = AddKeyword (#X_STATIC     , f0, s0, ks, t0, t0, t0, t0, "STATIC")
  1158.     #Q_STEP          = AddKeyword (#X_STEP       , f0, s0, ks, t0, t0, t0, t0, "STEP")
  1159.     #Q_STICK         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "STICK")
  1160.     #Q_STOP          = AddKeyword (#X_STOP       , f0, s0, ks, t0, t0, t0, t0, "STOP")
  1161.     #Q_STR_D         = AddKeyword (#X_STR_D      , f0, s0, ki, t0, t0, t0, t0, "STR$")
  1162.     #Q_STRIG         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "STRIG")
  1163.     #Q_STRING        = AddKeyword (#X_STRING     , f0, s0, k0, t0, t0, t0, t0, "STRING")
  1164.     #Q_STRING_D      = AddKeyword (#X_CHR_D      , f0, s0, ki, t0, t0, t0, t0, "STRING$")
  1165.     #Q_SUB           = AddKeyword (#X_FUNCTION   , f0, s0, ks, t0, t0, t0, t0, "SUB")
  1166.     #Q_SWAP          = AddKeyword (#X_SWAP       , f0, s0, ks, t0, t0, t0, t0, "SWAP")
  1167.     #Q_SYSTEM        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "SYSTEM")
  1168.     #Q_TAB           = AddKeyword (#X_TAB        , f0, s0, ki, t0, t0, t0, t0, "TAB")
  1169.     #Q_TAN           = AddKeyword (#X_TAN        , f0, s0, ki, t0, t0, t0, t0, "TAN")
  1170.     #Q_THEN          = AddKeyword (#X_THEN       , f0, s0, ks, t0, t0, t0, t0, "THEN")
  1171.     #Q_TIME_D        = AddKeyword (            x0, f0, s0, ki, t0, t0, t0, t0, "TIME$")
  1172.     #Q_TIMER         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "TIMER")
  1173.     #Q_TO            = AddKeyword (#X_TO         , f0, s0, ks, t0, t0, t0, t0, "TO")
  1174.     #Q_TROFF         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "TROFF")
  1175.     #Q_TRON          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "TRON")
  1176.     #Q_TYPE          = AddKeyword (#X_TYPE       , f0, s0, ks, t0, t0, t0, t0, "TYPE")
  1177.     #Q_UBOUND        = AddKeyword (#X_UBOUND     , f0, s0, ki, t0, t0, t0, t0, "UBOUND")
  1178.     #Q_UCASE_D       = AddKeyword (#X_UCASE_D    , f0, s0, ki, t0, t0, t0, t0, "UCASE$")
  1179.     #Q_UEVENT        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "UEVENT")
  1180.     #Q_UNLOCK        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "UNLOCK")
  1181.     #Q_UNTIL         = AddKeyword (#X_UNTIL      , f0, s0, ks, t0, t0, t0, t0, "UNTIL")
  1182.     #Q_UPDATE        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "UPDATE")
  1183.     #Q_USING         = AddKeyword (#X_FORMAT_D   , f0, s0, ks, t0, t0, t0, t0, "USING")
  1184.     #Q_VAL           = AddKeyword (#X_DOUBLE     , f0, s0, ki, t0, t0, t0, t0, "VAL")
  1185.     #Q_VARPTR        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "VARPTR")
  1186.     #Q_VARPTR_D      = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "VARPTR$")
  1187.     #Q_VARSEG        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "VARSEG")
  1188.     #Q_VIEW          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "VIEW")
  1189.     #Q_WAIT          = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "WAIT")
  1190.     #Q_WEND          = AddKeyword (#X_LOOP       , f0, s0, ks, t0, t0, t0, t0, "WEND")
  1191.     #Q_WHILE         = AddKeyword (#X_DO         , f0, s0, ks, t0, t0, t0, t0, "WHILE")
  1192.     #Q_WIDTH         = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "WIDTH")
  1193.     #Q_WINDOW        = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "WINDOW")
  1194.     #Q_WRITE         = AddKeyword (#X_WRITE      , f0, s0, ks, t0, t0, t0, t0, "WRITE")
  1195.     #Q_XOR           = AddKeyword (#X_XOR        , f0, s0, ko, t0, t0, t0, t0, "XOR")
  1196. '
  1197. '    #Q_POST_SSHORT   = AddKeyword (#X_POST_SSHORT, f0, s0, kc,  4, t0, t0, t0, "%")        ' part of string ???
  1198. '    #Q_POST_SLONG    = AddKeyword (#X_POST_SLONG , f0, s0, kc,  6, t0, t0, t0, "&")        ' part of string ???
  1199. '    #Q_POST_SINGLE   = AddKeyword (#X_POST_SINGLE, f0, s0, kc, 13, t0, t0, t0, "!")        ' part of string ???
  1200. '    #Q_POST_DOUBLE   = AddKeyword (#X_POST_DOUBLE, f0, s0, kc, 14, t0, t0, t0, "#")        ' part of string ???
  1201. '    #Q_POST_STRING   = AddKeyword (#X_POST_STRING, f0, s0, kc, 15, t0, t0, t0, "$")        ' part of string ???
  1202. '
  1203.     #Q_PLUS          = AddKeyword (#X_PLUS       , f0, s0, ko, t0, t0, t0, t0, "+")        ' unary
  1204.     #Q_MINUS         = AddKeyword (#X_MINUS      , f0, s0, ko, t0, t0, t0, t0, "-")        ' unary
  1205. '    #Q_ADDRESS       = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "&")        ' unary
  1206. '
  1207.     #Q_ADD           = AddKeyword (#X_ADD        , f0, s0, ko, t0, t0, t0, t0, "+")
  1208.     #Q_SUBTRACT      = AddKeyword (#X_SUBTRACT   , f0, s0, ko, t0, t0, t0, t0, "-")
  1209.     #Q_MULTIPLY      = AddKeyword (#X_MULTIPLY   , f0, s0, ko, t0, t0, t0, t0, "*")
  1210.     #Q_DIVIDE        = AddKeyword (#X_DIVIDE     , f0, s0, ko, t0, t0, t0, t0, "/")
  1211.     #Q_POWER         = AddKeyword (#X_POWER      , f0, s0, ko, t0, t0, t0, t0, "^")
  1212.     #Q_IDIVIDE       = AddKeyword (#X_IDIVIDE    , f0, s0, ko, t0, t0, t0, t0, "\\")
  1213.     #Q_REMAINDER     = AddKeyword (#X_MOD        , f0, s0, ko, t0, t0, t0, t0, "%")
  1214. '
  1215.     #Q_NOTBIT        = AddKeyword (#X_NOT        , f0, s0, ko, t0, t0, t0, t0, "~")        ' unary
  1216.     #Q_ANDBIT        = AddKeyword (#X_AND        , f0, s0, ko, t0, t0, t0, t0, "&")
  1217.     #Q_ORBIT         = AddKeyword (#X_OR         , f0, s0, ko, t0, t0, t0, t0, "|")
  1218.     #Q_EQ            = AddKeyword (#X_EQ         , f0, s0, ko, t0, t0, t0, t0, "=")
  1219.     #Q_NE            = AddKeyword (#X_NE         , f0, s0, ko, t0, t0, t0, t0, "<>")
  1220.     #Q_LT            = AddKeyword (#X_LT         , f0, s0, ko, t0, t0, t0, t0, "<")
  1221.     #Q_LE            = AddKeyword (#X_LE         , f0, s0, ko, t0, t0, t0, t0, "<=")
  1222.     #Q_GE            = AddKeyword (#X_GE         , f0, s0, ko, t0, t0, t0, t0, ">=")
  1223.     #Q_GT            = AddKeyword (#X_GT         , f0, s0, ko, t0, t0, t0, t0, ">")
  1224. '
  1225.     #Q_LPAREN        = AddKeyword (#X_LPAREN     , f0, s0, kc, t0, t0, t0, t0, "(")
  1226.     #Q_RPAREN        = AddKeyword (#X_RPAREN     , f0, s0, kc, t0, t0, t0, t0, ")")
  1227.     #Q_LBRAK         = AddKeyword (#X_LBRAK      , f0, s0, kc, t0, t0, t0, t0, "[")
  1228.     #Q_RBRAK         = AddKeyword (#X_RBRAK      , f0, s0, kc, t0, t0, t0, t0, "]")
  1229.     #Q_COMMA         = AddKeyword (#X_COMMA      , f0, s0, kc, t0, t0, t0, t0, ",")
  1230.     #Q_COLON         = AddKeyword (#X_COLON      , f0, s0, kc, t0, t0, t0, t0, ":")
  1231.     #Q_SEMI          = AddKeyword (#X_SEMI       , f0, s0, kc, t0, t0, t0, t0, ";")
  1232.  
  1233. '
  1234. '    #Q_KEYWORD       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "")
  1235. '    #Q_KEYWORD       = AddKeyword (            x0, f0, s0, k0, t0, t0, t0, t0, "")
  1236.     #qztoken         = #ntoken
  1237. END FUNCTION
  1238. '
  1239. '
  1240. ' #######################################
  1241. ' #####  InitializeXBasicTokens ()  #####
  1242. ' #######################################
  1243. '
  1244. FUNCTION  InitializeXBasicTokens ()
  1245. '
  1246. ' define shorthand variables to make function calls readable
  1247. '
  1248. ' common data-types
  1249. '
  1250.     t0 = 0
  1251.     ti = $$TYPE_XLONG            ' integer
  1252.     tg = $$TYPE_GIANT            ' giant-integer
  1253.     tf = $$TYPE_DOUBLE        ' floating-point
  1254.     ts = $$TYPE_STRING        ' nominal string
  1255. '
  1256. ' common kinds
  1257. '
  1258.     k0 = 0
  1259.     ks = $$KIND_XBASIC | $$KIND_STATEMENT
  1260.     ki = $$KIND_XBASIC | $$KIND_INTRINSIC
  1261.     ko = $$KIND_XBASIC | $$KIND_OPERATOR
  1262.     kk = $$KIND_XBASIC | $$KIND_KEYWORD
  1263.     kt = $$KIND_XBASIC | $$KIND_TYPE
  1264.     kl = $$KIND_XBASIC | $$KIND_LITERAL
  1265.     kf = $$KIND_XBASIC | $$KIND_FUNCTION
  1266.     ky = $$KIND_XBASIC | $$KIND_SYMBOL
  1267.     kv = $$KIND_XBASIC | $$KIND_VARIABLE
  1268.     ka = $$KIND_XBASIC | $$KIND_ARRAY
  1269.     kc = $$KIND_XBASIC | $$KIND_COMPOSITE
  1270.     ke = $$KIND_XBASIC | $$KIND_ELEMENT
  1271.     kh = $$KIND_XBASIC | $$KIND_CHARACTER
  1272.     km = $$KIND_XBASIC | $$KIND_FUNCTION        ' math library functions look like intrinsics
  1273.     kx = $$KIND_XBASIC
  1274. '
  1275. ' common kinds
  1276. '
  1277.     s0 = 0
  1278.     sa = $$SCOPE_AUTO
  1279.     sx = $$SCOPE_AUTOX
  1280.     sl = $$SCOPE_STATIC
  1281.     ss = $$SCOPE_SHARED
  1282.     se = $$SCOPE_EXTERNAL
  1283. '
  1284.     q0 = 0
  1285.     x0 = 0
  1286. '
  1287. '
  1288. ' token_number     = AddKeyword (translate, function, scope, kind, rtype, arg0, arg1, arg2, string$)
  1289. '
  1290.     #xatoken         = #ntoken + 1
  1291.     #X_ABS           = AddKeyword (#Q_ABS        , f0, s0, ki, tf, tf, t0, t0, "ABS")
  1292.     #X_ALL           = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "ALL")
  1293.     #X_AND           = AddKeyword (#Q_AND        , f0, s0, ko, t0, t0, t0, t0, "AND")
  1294.     #X_ANY           = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "ANY")
  1295.     #X_ASC           = AddKeyword (#Q_ASC        , f0, s0, ki, t0, t0, t0, t0, "ASC")
  1296.     #X_ATAN          = AddKeyword (#Q_ATN        , f0, s0, km, t0, t0, t0, t0, "ATAN")
  1297.     #X_ATTACH        = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "ATTACH")
  1298.     #X_AUTO          = AddKeyword (            q0, f0, sa, ks, t0, t0, t0, t0, "AUTO")
  1299.     #X_AUTOX         = AddKeyword (            q0, f0, sx, ks, t0, t0, t0, t0, "AUTOX")
  1300.     #X_BIN_D         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "BIN$")
  1301.     #X_BINB_D        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "BINB$")
  1302.     #X_BITFIELD      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "BITFIELD")
  1303.     #X_CASE          = AddKeyword (#Q_CASE       , f0, s0, ks, t0, t0, t0, t0, "CASE")
  1304.     #X_CFUNCTION     = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "CFUNCTION")
  1305.     #X_CHR_D         = AddKeyword (#Q_CHR_D      , f0, s0, ki, t0, t0, t0, t0, "CHR$")
  1306.     #X_CJUST_D       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "CJUST$")
  1307.     #X_CLOSE         = AddKeyword (#Q_CLOSE      , f0, s0, ki, t0, t0, t0, t0, "CLOSE")
  1308.     #X_CLR           = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "CLR")
  1309.     #X_CSIZE         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "CSIZE")
  1310.     #X_CSIZE_D       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "CSIZE$")
  1311.     #X_CSTRING_D     = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "CSTRING$")
  1312.     #X_DEC           = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "DEC")
  1313.     #X_DECLARE       = AddKeyword (#Q_DECLARE    , f0, s0, ks, t0, t0, t0, t0, "DECLARE")
  1314.     #X_DHIGH         = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "DHIGH")
  1315.     #X_DIM           = AddKeyword (#Q_DIM        , f0, s0, ki, t0, t0, t0, t0, "DIM")
  1316.     #X_DLOW          = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "DLOW")
  1317.     #X_DMAKE         = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "DMAKE")
  1318.     #X_DO            = AddKeyword (#Q_DO         , f0, s0, ks, t0, t0, t0, t0, "DO")
  1319.     #X_DOUBLE        = AddKeyword (#Q_DOUBLE     , f0, s0, ks, t0, t0, t0, t0, "DOUBLE")
  1320.     #X_DOUBLE        = AddKeyword (#Q_DOUBLE     , f0, s0, ki, t0, t0, t0, t0, "DOUBLE")
  1321.     #X_DOUBLEAT      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "DOUBLEAT")
  1322.     #X_ELSE          = AddKeyword (#Q_ELSE       , f0, s0, ks, t0, t0, t0, t0, "ELSE")
  1323.     #X_END           = AddKeyword (#Q_END        , f0, s0, ks, t0, t0, t0, t0, "END")
  1324.     #X_ENDIF         = AddKeyword (#Q_ENDIF      , f0, s0, ks, t0, t0, t0, t0, "ENDIF")
  1325.     #X_EOF           = AddKeyword (#Q_EOF        , f0, s0, ki, t0, t0, t0, t0, "EOF")
  1326.     #X_ERROR         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "ERROR")
  1327.     #X_EXIT          = AddKeyword (#Q_EXIT       , f0, s0, ks, t0, t0, t0, t0, "EXIT")
  1328.     #X_EXP           = AddKeyword (#Q_EXP        , f0, s0, km, t0, t0, t0, t0, "EXP")
  1329.     #X_EXTERNAL      = AddKeyword (            q0, f0, se, ks, t0, t0, t0, t0, "EXTERNAL")
  1330.     #X_EXTS          = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "EXTS")
  1331.     #X_EXTU          = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "EXTU")
  1332.     #X_FALSE         = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "FALSE")
  1333.     #X_FIX           = AddKeyword (#Q_FIX        , f0, s0, ki, t0, t0, t0, t0, "FIX")
  1334.     #X_FOR           = AddKeyword (#Q_FOR        , f0, s0, ks, t0, t0, t0, t0, "FOR")
  1335.     #X_FORMAT_D      = AddKeyword (#Q_USING      , f0, s0, ki, t0, t0, t0, t0, "FORMAT$")
  1336.     #X_FUNCADDR      = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "FUNCADDR")
  1337.     #X_FUNCADDR      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "FUNCADDR")
  1338.     #X_FUNCADDRAT    = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "FUNCADDRAT")
  1339.     #X_FUNCADDRESS   = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "FUNCADDRESS")
  1340.     #X_FUNCTION      = AddKeyword (#Q_FUNCTION   , f0, s0, ks, t0, t0, t0, t0, "FUNCTION")
  1341.     #X_GHIGH         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "GHIGH")
  1342.     #X_GIANT         = AddKeyword (#Q_GIANT      , f0, s0, ks, t0, t0, t0, t0, "GIANT")
  1343.     #X_GIANT         = AddKeyword (#Q_GIANT      , f0, s0, ki, t0, t0, t0, t0, "GIANT")
  1344.     #X_GIANTAT       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "GIANTAT")
  1345.     #X_GLOW          = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "GLOW")
  1346.     #X_GMAKE         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "GMAKE")
  1347.     #X_GOADDR        = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "GOADDR")
  1348.     #X_GOADDR        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "GOADDR")
  1349.     #X_GOADDRAT      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "GOADDRAT")
  1350.     #X_GOADDRESS     = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "GOADDRESS")
  1351.     #X_GOSUB         = AddKeyword (#Q_GOSUB      , f0, s0, ks, t0, t0, t0, t0, "GOSUB")
  1352.     #X_GOTO          = AddKeyword (#Q_GOTO       , f0, s0, ks, t0, t0, t0, t0, "GOTO")
  1353.     #X_HEX_D         = AddKeyword (#Q_HEX_D      , f0, s0, ki, t0, t0, t0, t0, "HEX$")
  1354.     #X_HEXX_D        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "HEXX$")
  1355.     #X_HIGH0         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "HIGH0")
  1356.     #X_HIGH1         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "HIGH1")
  1357.     #X_IF            = AddKeyword (#Q_IF         , f0, s0, ks, t0, t0, t0, t0, "IF")
  1358.     #X_IFF           = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "IFF")
  1359.     #X_IFT           = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "IFT")
  1360.     #X_IFZ           = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "IFZ")
  1361.     #X_INC           = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "INC")
  1362.     #X_INCHR         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "INCHR")
  1363.     #X_INCHRI        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "INCHRI")
  1364.     #X_INT           = AddKeyword (#Q_INT        , f0, s0, ki, t0, t0, t0, t0, "INT")
  1365.     #X_INTERNAL      = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "INTERNAL")
  1366.     #X_LCASE_D       = AddKeyword (#Q_LCASE_D    , f0, s0, ki, t0, t0, t0, t0, "LCASE$")
  1367.     #X_LCLIP_D       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "LCLIP$")
  1368.     #X_LEFT_D        = AddKeyword (#Q_LEFT_D     , f0, s0, ki, t0, t0, t0, t0, "LEFT$")
  1369.     #X_LEN           = AddKeyword (#Q_LEN        , f0, s0, ki, t0, t0, t0, t0, "LEN")
  1370.     #X_LJUST_D       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "LJUST$")
  1371.     #X_LOF           = AddKeyword (#Q_LOF        , f0, s0, ki, t0, t0, t0, t0, "LOF")
  1372.     #X_LOG           = AddKeyword (#Q_LOG        , f0, s0, km, t0, t0, t0, t0, "LOG")
  1373.     #X_LOOP          = AddKeyword (#Q_LOOP       , f0, s0, ks, t0, t0, t0, t0, "LOOP")
  1374.     #X_LTRIM_D       = AddKeyword (#Q_LTRIM_D    , f0, s0, ki, t0, t0, t0, t0, "LTRIM$")
  1375.     #X_MAKE          = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "MAKE")
  1376.     #X_MAX           = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "MAX")
  1377.     #X_MID_D         = AddKeyword (#Q_MID_D      , f0, s0, ki, t0, t0, t0, t0, "MID$")
  1378.     #X_MIN           = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "MIN")
  1379.     #X_MOD           = AddKeyword (#Q_MOD        , f0, s0, ko, t0, t0, t0, t0, "MOD")
  1380.     #X_NEXT          = AddKeyword (#Q_NEXT       , f0, s0, ks, t0, t0, t0, t0, "NEXT")
  1381.     #X_NOT           = AddKeyword (#Q_NOT        , f0, s0, ko, t0, t0, t0, t0, "NOT")
  1382.     #X_NULL_D        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "NULL$")
  1383.     #X_OCT_D         = AddKeyword (#Q_OCT_D      , f0, s0, ki, t0, t0, t0, t0, "OCT$")
  1384.     #X_OCTO_D        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "OCTO$")
  1385.     #X_OPEN          = AddKeyword (#Q_OPEN       , f0, s0, ki, t0, t0, t0, t0, "OPEN")
  1386.     #X_OR            = AddKeyword (#Q_OR         , f0, s0, ko, t0, t0, t0, t0, "OR")
  1387.     #X_POF           = AddKeyword (#Q_POF        , f0, s0, ki, t0, t0, t0, t0, "POF")
  1388.     #X_PRINT         = AddKeyword (#Q_PRINT      , f0, s0, ks, t0, t0, t0, t0, "PRINT")
  1389.     #X_PROGRAM       = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "PROGRAM")
  1390.     #X_QUIT          = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "QUIT")
  1391.     #X_RCLIP_D       = AddKeyword (#Q_RCLIP_D    , f0, s0, ki, t0, t0, t0, t0, "RCLIP$")
  1392.     #X_READ          = AddKeyword (#Q_READ       , f0, s0, ks, t0, t0, t0, t0, "READ")
  1393.     #X_REDIM         = AddKeyword (#Q_REDIM      , f0, s0, ks, t0, t0, t0, t0, "REDIM")
  1394.     #X_RETURN        = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "RETURN")
  1395.     #X_RIGHT_D       = AddKeyword (#Q_RIGHT_D    , f0, s0, ki, t0, t0, t0, t0, "RIGHT$")
  1396.     #X_RINCHR        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "RINCHR")
  1397.     #X_RINCHRI       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "RINCHRI")
  1398.     #X_RINSTR        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "RINSTR")
  1399.     #X_RINSTRI       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "RINSTRI")
  1400.     #X_RJUST_D       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "RJUST$")
  1401.     #X_ROTATER       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "ROTATER")
  1402.     #X_RTRIM_D       = AddKeyword (#Q_RTRIM_D    , f0, s0, ki, t0, t0, t0, t0, "RTRIM$")
  1403.     #X_SBYTE         = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "SBYTE")
  1404.     #X_SBYTE         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SBYTE")
  1405.     #X_SBYTEAT       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SBYTEAT")
  1406.     #X_SEEK          = AddKeyword (#Q_SEEK       , f0, s0, ki, t0, t0, t0, t0, "SEEK")
  1407.     #X_SELECT        = AddKeyword (#Q_SELECT     , f0, s0, ks, t0, t0, t0, t0, "SELECT")
  1408.     #X_SET           = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SET")
  1409.     #X_SGN           = AddKeyword (#Q_SGN        , f0, s0, ki, t0, t0, t0, t0, "SGN")
  1410.     #X_SFUNCTION     = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "SFUNCTION")
  1411.     #X_SHARED        = AddKeyword (#Q_SHARED     , f0, s0, ks, t0, t0, t0, t0, "SHARED")
  1412.     #X_SHELL         = AddKeyword (#Q_SHELL      , f0, ss, ki, t0, t0, t0, t0, "SHELL")
  1413.     #X_SIGN          = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SIGN")
  1414.     #X_SIGNED_D      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SIGNED$")
  1415.     #X_SIN           = AddKeyword (#Q_SIN        , f0, s0, km, t0, t0, t0, t0, "SIN")
  1416.     #X_SINGLE        = AddKeyword (#Q_SINGLE     , f0, s0, ks, t0, t0, t0, t0, "SINGLE")
  1417.     #X_SINGLE        = AddKeyword (#Q_SINGLE     , f0, s0, ki, t0, t0, t0, t0, "SINGLE")
  1418.     #X_SINGLEAT      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SINGLEAT")
  1419.     #X_SIZE          = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SIZE")
  1420.     #X_SLONG         = AddKeyword (#Q_LONG       , f0, s0, ks, t0, t0, t0, t0, "SLONG")
  1421.     #X_SLONG         = AddKeyword (#Q_LONG       , f0, s0, ki, t0, t0, t0, t0, "SLONG")
  1422.     #X_SLONGAT       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SLONGAT")
  1423.     #X_SMAKE         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SMAKE")
  1424.     #X_SPACE_D       = AddKeyword (#Q_SPACE_D    , f0, s0, ki, t0, t0, t0, t0, "SPACE$")
  1425.     #X_SSHORT        = AddKeyword (#Q_SHORT      , f0, s0, ks, t0, t0, t0, t0, "SSHORT")
  1426.     #X_SSHORT        = AddKeyword (#Q_SHORT      , f0, s0, ki, t0, t0, t0, t0, "SSHORT")
  1427.     #X_SSHORTAT      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SSHORTAT")
  1428.     #X_SQRT          = AddKeyword (#Q_INTEGER    , f0, s0, km, t0, t0, t0, t0, "SQRT")
  1429.     #X_STATIC        = AddKeyword (#Q_STATIC     , f0, sl, ks, t0, t0, t0, t0, "STATIC")
  1430.     #X_STEP          = AddKeyword (#Q_STEP       , f0, s0, ks, t0, t0, t0, t0, "STEP")
  1431.     #X_STOP          = AddKeyword (#Q_STOP       , f0, s0, ks, t0, t0, t0, t0, "STOP")
  1432.     #X_STR_D         = AddKeyword (#Q_STR_D      , f0, s0, ki, t0, t0, t0, t0, "STR$")
  1433.     #X_STRING        = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "STRING")
  1434.     #X_STRING        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "STRING")
  1435.     #X_STRING_D      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "STRING$")
  1436.     #X_STUFF_D       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "STUFF$")
  1437.     #X_SUB           = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "SUB")
  1438.     #X_SUBADDR       = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "SUBADDR")
  1439.     #X_SUBADDR       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SUBADDR")
  1440.     #X_SUBADDRAT     = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SUBADDRAT")
  1441.     #X_SUBADDRESS    = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "SUBADDRESS")
  1442.     #X_SWAP          = AddKeyword (#Q_SWAP       , f0, s0, ki, t0, t0, t0, t0, "SWAP")
  1443.     #X_TAB           = AddKeyword (#Q_TAB        , f0, s0, ki, t0, t0, t0, t0, "TAB")
  1444.     #X_TAN           = AddKeyword (#Q_TAN        , f0, s0, km, t0, t0, t0, t0, "TAN")
  1445.     #X_THEN          = AddKeyword (#Q_THEN       , f0, s0, ks, t0, t0, t0, t0, "THEN")
  1446.     #X_TO            = AddKeyword (#Q_TO         , f0, s0, ks, t0, t0, t0, t0, "TO")
  1447.     #X_TRIM_D        = AddKeyword (#Q_TRIM_D     , f0, s0, ki, t0, t0, t0, t0, "TRIM$")
  1448.     #X_TYPE          = AddKeyword (#Q_TYPE       , f0, s0, ks, t0, t0, t0, t0, "TYPE")
  1449.     #X_UBOUND        = AddKeyword (#Q_UBOUND     , f0, s0, ki, t0, t0, t0, t0, "UBOUND")
  1450.     #X_UBYTE         = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "UBYTE")
  1451.     #X_UBYTE         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "UBYTE")
  1452.     #X_UBYTEAT       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "UBYTEAT")
  1453.     #X_UCASE_D       = AddKeyword (#Q_UCASE_D    , f0, s0, ki, t0, t0, t0, t0, "UCASE$")
  1454.     #X_ULONG         = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "ULONG")
  1455.     #X_ULONG         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "ULONG")
  1456.     #X_ULONGAT       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "ULONGAT")
  1457.     #X_UNION         = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "UNION")
  1458.     #X_UNTIL         = AddKeyword (#Q_UNTIL      , f0, s0, ks, t0, t0, t0, t0, "UNTIL")
  1459.     #X_USHORT        = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "USHORT")
  1460.     #X_USHORT        = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "USHORT")
  1461.     #X_USHORTAT      = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "USHORTAT")
  1462.     #X_VOID          = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "VOID")
  1463.     #X_WHILE         = AddKeyword (#Q_WHILE      , f0, s0, ks, t0, t0, t0, t0, "WHILE")
  1464.     #X_WRITE         = AddKeyword (#Q_WRITE      , f0, s0, ks, t0, t0, t0, t0, "WRITE")
  1465.     #X_XLONG         = AddKeyword (            q0, f0, s0, ks, t0, t0, t0, t0, "XLONG")
  1466.     #X_XLONG         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "XLONG")
  1467.     #X_XLONGAT       = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "XLONGAT")
  1468.     #X_XMAKE         = AddKeyword (            q0, f0, s0, ki, t0, t0, t0, t0, "XMAKE")
  1469.     #X_XOR           = AddKeyword (#Q_XOR        , f0, s0, ko, t0, t0, t0, t0, "XOR")
  1470. '
  1471.     #X_PRE_BYREF     = AddKeyword (            q0, f0, s0, kh, t0, t0, t0, t0, "@")
  1472.     #X_PRE_SHARED    = AddKeyword (            q0, f0, s5, kh, t0, t0, t0, t0, "#")
  1473.     #X_PRE_EXTERNAL  = AddKeyword (            q0, f0, s7, kh, t0, t0, t0, t0, "##")
  1474. '
  1475. '    #X_POST_SBYTE    = AddKeyword (            q0, f0, s0, kh,  2, t0, t0, t0, "@")        ' part of symbol
  1476. '    #X_POST_UBYTE    = AddKeyword (            q0, f0, s0, kh,  3, t0, t0, t0, "@@")    ' part of symbol
  1477. '    #X_POST_SSHORT   = AddKeyword (#Q_POST_SSHORT, f0, s0, kh,  4, t0, t0, t0, "%")        ' part of symbol
  1478. '    #X_POST_USHORT   = AddKeyword (            q0, f0, s0, kh,  5, t0, t0, t0, "%%")    ' part of symbol
  1479. '    #X_POST_SLONG    = AddKeyword (#Q_POST_SLONG , f0, s0, kh,  6, t0, t0, t0, "&")        ' part of symbol
  1480. '    #X_POST_ULONG    = AddKeyword (            q0, f0, s0, kh,  7, t0, t0, t0, "&&")    ' part of symbol
  1481. '    #X_POST_XLONG    = AddKeyword (            q0, f0, s0, kh,  8, t0, t0, t0, "~")        ' part of symbol
  1482. '    #X_POST_GIANT    = AddKeyword (            q0, f0, s0, kh, 12, t0, t0, t0, "$$")    ' part of symbol
  1483. '    #X_POST_SINGLE   = AddKeyword (#Q_POST_SINGLE, f0, s0, kh, 13, t0, t0, t0, "!")        ' part of symbol
  1484. '    #X_POST_DOUBLE   = AddKeyword (#Q_POST_DOUBLE, f0, s0, kh, 14, t0, t0, t0, "#")        ' part of symbol
  1485. '    #X_POST_STRING   = AddKeyword (#Q_POST_STRING, f0, s0, kh, 15, t0, t0, t0, "$")        ' part of symbol
  1486. '
  1487.     #X_PLUS          = AddKeyword (#Q_PLUS       , f0, s0, ko, t0, t0, t0, t0, "+")        ' unary
  1488.     #X_MINUS         = AddKeyword (#Q_MINUS      , f0, s0, ko, t0, t0, t0, t0, "-")        ' unary
  1489.     #X_ADDRESS       = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "&")        ' unary
  1490. '
  1491.     #X_ADD           = AddKeyword (#Q_ADD        , f0, s0, ko, t0, t0, t0, t0, "+")
  1492.     #X_SUBTRACT      = AddKeyword (#Q_SUBTRACT   , f0, s0, ko, t0, t0, t0, t0, "-")
  1493.     #X_MULTIPLY      = AddKeyword (#Q_MULTIPLY   , f0, s0, ko, t0, t0, t0, t0, "*")
  1494.     #X_DIVIDE        = AddKeyword (#Q_DIVIDE     , f0, s0, ko, t0, t0, t0, t0, "/")
  1495.     #X_POWER         = AddKeyword (#Q_POWER      , f0, s0, ko, t0, t0, t0, t0, "**")
  1496.     #X_IDIVIDE       = AddKeyword (#Q_IDIVIDE    , f0, s0, ko, t0, t0, t0, t0, "\\")
  1497.     #X_REMAINDER     = AddKeyword (#Q_MOD        , f0, s0, ko, t0, t0, t0, t0, "%")
  1498. '
  1499.     #X_USHIFT        = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "<<<")
  1500.     #X_DSHIFT        = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, ">>>")
  1501.     #X_LSHIFT        = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "<<")
  1502.     #X_RSHIFT        = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, ">>")
  1503.     #X_NOTBIT        = AddKeyword (#Q_NOT        , f0, s0, ko, t0, t0, t0, t0, "~")
  1504.     #X_ANDBIT        = AddKeyword (#Q_AND        , f0, s0, ko, t0, t0, t0, t0, "&")
  1505.     #X_ORBIT         = AddKeyword (#Q_OR         , f0, s0, ko, t0, t0, t0, t0, "|")
  1506.     #X_TESTL         = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "!!")
  1507.     #X_NOTL          = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "!")
  1508.     #X_ANDL          = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "&&")
  1509.     #X_XORL          = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "^^")
  1510.     #X_ORL           = AddKeyword (            q0, f0, s0, ko, t0, t0, t0, t0, "||")
  1511.     #X_EQ            = AddKeyword (#Q_EQ         , f0, s0, ko, t0, t0, t0, t0, "=")
  1512.     #X_NE            = AddKeyword (#Q_NE         , f0, s0, ko, t0, t0, t0, t0, "<>")
  1513.     #X_LT            = AddKeyword (#Q_LT         , f0, s0, ko, t0, t0, t0, t0, "<")
  1514.     #X_LE            = AddKeyword (#Q_LE         , f0, s0, ko, t0, t0, t0, t0, "<=")
  1515.     #X_GE            = AddKeyword (#Q_GE         , f0, s0, ko, t0, t0, t0, t0, ">=")
  1516.     #X_GT            = AddKeyword (#Q_GT         , f0, s0, ko, t0, t0, t0, t0, ">")
  1517.     #X_EQU           = AddKeyword (#Q_EQ         , f0, s0, ko, t0, t0, t0, t0, "==")
  1518.     #X_NEQ           = AddKeyword (#Q_NE         , f0, s0, ko, t0, t0, t0, t0, "!=")
  1519.     #X_NGE           = AddKeyword (#Q_LT         , f0, s0, ko, t0, t0, t0, t0, "!>=")
  1520.     #X_NGT           = AddKeyword (#Q_LE         , f0, s0, ko, t0, t0, t0, t0, "!>")
  1521.     #X_NLE           = AddKeyword (#Q_GE         , f0, s0, ko, t0, t0, t0, t0, "!<")
  1522.     #X_NLT           = AddKeyword (#Q_GT         , f0, s0, ko, t0, t0, t0, t0, "!<=")
  1523. '
  1524. '    #X_KEYWORD       = AddKeyword (            q0, f0, s0, k0, t0, t0, t0, t0, "")
  1525. '    #X_KEYWORD       = AddKeyword (            q0, f0, s0, k0, t0, t0, t0, t0, "")
  1526.     #xztoken         = #ntoken
  1527. END FUNCTION
  1528. '
  1529. '
  1530. ' ##################################
  1531. ' #####  LoadQBasicProgram ()  #####
  1532. ' ##################################
  1533. '
  1534. FUNCTION  LoadQBasicProgram (@qbasic$[])
  1535. '
  1536.     DIM qbasic$[]                                                                        ' empty qbasic$[]
  1537. ' print = $$TRUE                                                                    ' print for debugging
  1538.     XstGetCommandLineArguments (@count, @arg$[])        ' arg$[1] = QBasic program filename
  1539. '
  1540. ' input filename of QBasic program if no command line argument
  1541. '
  1542.     IF (count < 2) THEN
  1543.         qfile$ = INLINE$ ("input filename of QuickBasic file ===>> ")
  1544.         IFZ qfile$ THEN qfile$ = "qbasic.bas"
  1545.     ELSE
  1546.         qfile$ = arg$[1]
  1547.     END IF
  1548. '
  1549. ' qfile$ = filename of QBasic program - must be ASCII
  1550. '
  1551.     IFZ qbasic$[] THEN
  1552.         XstLoadStringArray (@qfile$, @qbasic$[])    ' qbasic$[] = QBasic program
  1553.     END IF
  1554. '
  1555.     IFZ qbasic$[] THEN
  1556.         dot = RINSTR (qfile$, ".")
  1557.         IF dot THEN file$ = LEFT$ (qfile$, dot-1)
  1558.     END IF
  1559. '
  1560.     IFZ qbasic$[] THEN
  1561.         qfile$ = file$ + ".bas"
  1562.         XstLoadStringArray (@qfile$, @qbasic$[])    ' qbasic$[] = QBasic program
  1563.     END IF
  1564. '
  1565.     IFZ qbasic$[] THEN
  1566.         qfile$ = file$ + ".x"
  1567.         XstLoadStringArray (@qfile$, @qbasic$[])    ' qbasic$[] = QBasic program
  1568.     END IF
  1569. '
  1570. ' print QBasic program during testing
  1571. '
  1572.     uline = UBOUND (qbasic$[])                                    ' upper bound of QBasic array
  1573.     FOR line = 0 TO uline                                                ' for all lines of QBasic source
  1574.         line$ = RTRIM$(qbasic$[line])                            ' line$ = next line of QBasic program
  1575.         IF line$ THEN topline = line                            ' this could be the final QBasic line
  1576.         IF print THEN PRINT line$                                    ' perhaps print the QBasic line
  1577.         qbasic$[line] = line$                                            ' replace trimmed line
  1578.     NEXT line
  1579. '
  1580.     IF (topline != uline) THEN REDIM qbasic$[topline]
  1581. END FUNCTION
  1582. '
  1583. '
  1584. ' ###############################
  1585. ' #####  QBasicToXBasic ()  #####
  1586. ' ###############################
  1587. '
  1588. FUNCTION  QBasicToXBasic (@qb$[], @xb$[])
  1589. '
  1590.     DIM xb$[]                                                        ' no XBasic source
  1591.     IFZ qb$[] THEN RETURN                                ' no QBasic source
  1592. '
  1593.     Initialize ()                                                ' initialize everything
  1594. '
  1595.     DIM #qbasic$[]                                            '
  1596.     DIM #xbasic$[]                                            ' no XBasic source yet
  1597.     SWAP #qbasic$[], qb$[]                            ' make QBasic source SHARED
  1598. '
  1599.     ParseQBasic ()                                            ' convert #qbasic$[] source into tokens in #program[]
  1600.     Translate ()                                                ' translate #program[] tokens into xbasic$[] source code
  1601. '
  1602.     SWAP #qbasic$[], qb$[]                            ' restore QBasic source
  1603.     SWAP #xbasic$[], xb$[]                            ' return XBasic source
  1604. END FUNCTION
  1605. '
  1606. '
  1607. ' ############################
  1608. ' #####  ParseQBasic ()  #####
  1609. ' ############################
  1610. '
  1611. FUNCTION  ParseQBasic ()
  1612. '
  1613.     IFZ #qbasic$[] THEN RETURN                    ' no QBasic source program
  1614.     #quline = UBOUND (#qbasic$[])                ' last line in QBasic source
  1615. '
  1616. ' parse QBasic program into tokens-numbers in #program[function,line,token]
  1617. ' creates symbol table in #token[] and #string$[]
  1618. '
  1619.     line = 0
  1620.     uline = 4095
  1621.     DIM line[uline,]
  1622. '
  1623.     #function = 0
  1624. '
  1625.     FOR i = 0 TO #quline                                            ' for all QBasic lines
  1626.         DIM token[]                                                            ' start with zero tokens
  1627.         function = #function                                        ' remember this function-number
  1628.         qbasic$ = #qbasic$[i]                                        ' next line of QBasic source-code
  1629.         qbasicline$ = qbasic$                                        '
  1630.         ParseSourceLine (@qbasic$, @token[])        ' parse this line into tokens
  1631.         IF #print THEN PRINT                                        '
  1632.         IF #print THEN PRINT qbasic$                        '
  1633.         IF #print THEN DeparseTokens (@token[], @line$) : PRINT line$
  1634.         IF token[] THEN
  1635.             IF (function != #function) THEN                ' first executable line of new function
  1636.                 DEC line                                                        ' this line goes in the next function
  1637.                 REDIM line[line,]                                        ' array size = number of lines in function
  1638.                 IF (#ufunction < #function) THEN
  1639.                     #ufunction = #ufunction + 1024        ' add 1024 lines to this function
  1640.                     REDIM #program[#ufunction,]                ' make room for new lines of tokens in function
  1641.                 END IF
  1642.                 SWAP #program[#function,], line[]        ' attach lines of tokens to program function
  1643.                 INC #function                                                ' next function number
  1644.                 line = 0                                                        ' first line in new function
  1645.                 uline = 4095                                                ' default number of lines in new function
  1646.                 DIM line[uline,]                                        ' make room for lines of tokens in new function
  1647.             END IF
  1648.         END IF
  1649.         IF (line > uline) THEN                                    ' more lines than array space
  1650.             uline = uline + 256                                        ' allow room for 256 more lines
  1651.             REDIM line[uline,]                                        ' make room for more lines of tokens
  1652.         END IF
  1653.         SWAP line[line,], token[]                                ' add tokens to program
  1654.     NEXT i
  1655. END FUNCTION
  1656. '
  1657. '
  1658. ' ##########################
  1659. ' #####  Translate ()  #####
  1660. ' ##########################
  1661. '
  1662. FUNCTION  Translate ()
  1663.     XLONG  function[]
  1664.     XLONG  line[]
  1665. '
  1666.     #xline = 0                                                                                ' start at beginning
  1667.     DIM #xbasic$[]                                                                        ' start with no XBasic
  1668.     IFZ #program[] THEN RETURN                                                ' no QBasic program tokens
  1669.     XstLoadStringArray (@"start.txt", @start$[])            ' get standard XBasic startup
  1670.     IFZ start$[] THEN RETURN                                                    ' support text-file missing
  1671.     #xuline = #quline << 1                                                        ' double room for XBasic
  1672.     DIM xbasic$[#xuline]                                                            ' array to hold XBasic
  1673.     OutputXBasic (@start$[])                                                    ' startup #xbasic$[]
  1674. '
  1675. '
  1676. ' translate QBasic tokens in #program[function,line,token] into XBasic source
  1677. '
  1678.     line = 0
  1679.     token = 0
  1680.     #function = 0
  1681.     #ufunction = UBOUND (#program[])
  1682. '
  1683.     DIM func[]
  1684.     DIM line[]
  1685. '
  1686.     FOR function = 0 TO ufunction                                            ' for all functions in program
  1687.         SWAP #program[#function,], function[]                        ' function[] = tokens for function
  1688.         uline = UBOUND (function[])                                            ' # of lines in this function
  1689.         #function = function                                                        ' #function = this function
  1690.         FOR line = 0 TO uline                                                        ' for all lines in function
  1691.             SWAP function[line,], line[]                                    ' line[] = tokens for next line
  1692.             TranslateLine (@line[])                                                ' translate QBasic tokens to XBasic source
  1693.         NEXT line                                                                                '
  1694.     NEXT function
  1695. END FUNCTION
  1696. '
  1697. '
  1698. ' ##############################
  1699. ' #####  TranslateLine ()  #####
  1700. ' ##############################
  1701. '
  1702. FUNCTION  TranslateLine (line[])
  1703. '
  1704.     ntoken = 0
  1705.     IFZ line[] THEN RETURN
  1706.     utoken = UBOUND (line[])
  1707. '
  1708. ' translate all statements on line
  1709. '
  1710.     DO
  1711.         done = TranslateStatement (@line[], @ntoken)
  1712.         IF (ntoken > utoken) THEN EXIT DO
  1713.     LOOP UNTIL done
  1714. END FUNCTION
  1715. '
  1716. '
  1717. ' ###################################
  1718. ' #####  TranslateStatement ()  #####
  1719. ' ###################################
  1720. '
  1721. FUNCTION  TranslateStatement (line[], ntoken)
  1722.  
  1723.  
  1724. END FUNCTION
  1725. '
  1726. '
  1727. ' ##############################
  1728. ' #####  DeparseTokens ()  #####
  1729. ' ##############################
  1730. '
  1731. FUNCTION  DeparseTokens (token[], line$)
  1732. '
  1733.     line$ = ""
  1734.     IFZ token[] THEN RETURN
  1735. '
  1736.     upper = UBOUND (token[])
  1737. '
  1738.     FOR i = 0 TO upper
  1739.         token = token[i]
  1740.         IFZ token THEN DO NEXT
  1741.         whitestring = token >> 24
  1742.         token = token AND 0x00FFFFFF
  1743.         IF whitestring THEN line$ = line$ + #whitestring$[whitestring]
  1744.         IF (token <= #utoken) THEN
  1745.             line$ = line$ + #string$[#token[token].string]
  1746.         END IF
  1747.     NEXT i
  1748. END FUNCTION
  1749. '
  1750. '
  1751. ' ################################
  1752. ' #####  ParseSourceLine ()  #####  parse line of QBasic source into tokens
  1753. ' ################################
  1754. '
  1755. FUNCTION  ParseSourceLine (@line$, @line[])
  1756.     STATIC  FUNCADDR  XLONG  parseFunction[] (STRING, XLONG)
  1757. '
  1758.     IFZ parseFunction[] THEN GOSUB LoadParseFunctionArray
  1759. '
  1760.     offset = 0                                                                ' offset to next character in line$
  1761.     DIM line[]                                                                ' start with nothing on line
  1762.     DIM #line[]                                                                ' start with no tokens on line
  1763.     #whitebyte = 0                                                        ' leading whitespace byte = zero
  1764.     #nlinetoken = 0                                                        ' where to put next token in #line[]
  1765.     #ulinetoken = 255                                                    ' upper bound of #line[] of tokens
  1766.     DIM #line[#ulinetoken]                                        ' make room for plenty of tokens
  1767.     #functionLine = $$FALSE                                        ' not function definition line
  1768. '
  1769.     IFZ line$ THEN RETURN                                            ' empty line
  1770.     uchar = UBOUND (line$)                                        ' uchar = upper character in line$
  1771. '
  1772. ' parse the line - one language element at a time
  1773. '
  1774.     DO                                                                                                                            ' all characters on line
  1775.         char = line${offset}                                                                                    ' get next character on line
  1776.         token = @parseFunction[char] (@line$, @offset)                                ' call appropriate function to process
  1777.         token = token AND 0x00FFFFFF                                                                    ' remove whitestring from token
  1778.         IFZ token THEN EXIT DO                                                                                ' zero token means end of line
  1779. '
  1780.         IF (#ntoken == 1) THEN                                                                                ' first important token on line
  1781.             IF ((token == #Q_FUNCTION) OR (token == #Q_SUB)) THEN                ' first line of new function
  1782.                 INC #function                                                                                            ' next function
  1783.             END IF
  1784.         END IF
  1785.     LOOP WHILE (offset <= uchar)
  1786. '
  1787.     IFZ #nlinetoken THEN                                            ' nothing but whitespace = blank line
  1788.         DIM #line[]                                                            '
  1789.         DIM line[]                                                            '
  1790.     ELSE                                                                            '
  1791.         REDIM #line[#nlinetoken]                                ' resize token array to minimum
  1792.         #line[#nlinetoken] = 0                                    ' null terminate just in case
  1793.         SWAP line[], #line[]                                        ' return line[] of tokens
  1794.     END IF                                                                        '
  1795. '
  1796.     RETURN                                                                        ' end of function
  1797. '
  1798. '
  1799. '
  1800. ' ****************************************
  1801. ' *****  SUB LoadParseFunctionArray  *****
  1802. ' ****************************************
  1803. '
  1804. ' Array parseFunction[] contains the addresses of the functions that
  1805. ' should parse the next language-element, based on its 1st character.
  1806. ' For example, if the first character of a language-element is "0"-"9",
  1807. ' the language-element is some kind of number.  "+","-",etc = operators.
  1808. ' "A"-"Z", "a"-"z", "_" = some kind of symbol.  space & tab = whitespace.
  1809. '
  1810. ' #####  NOTE  #####
  1811. '
  1812. ' The following character ranges are more-or-less correct for XBasic,
  1813. ' but almost certainly need a little modification for QBasic.
  1814. '
  1815. SUB LoadParseFunctionArray
  1816.     DIM parseFunction[255]
  1817.     FOR c = 0 TO 255
  1818.         SELECT CASE TRUE
  1819.             CASE (c >= 128)    : parseFunction[c] = &ParseWhitespace()        ' convert trash to spaces
  1820.             CASE (c >= 123)    : parseFunction[c] = &ParseCharacter()        ' character or operator
  1821.             CASE (c >=  97)    : parseFunction[c] = &ParseSymbol()                ' "a-z"
  1822.             CASE (c ==  95)    : parseFunction[c] = &ParseSymbol()                ' "_"
  1823.             CASE (c >=  91)    : parseFunction[c] = &ParseCharacter()        ' character or operator
  1824.             CASE (c >=  65)    : parseFunction[c] = &ParseSymbol()                ' "A-Z"
  1825.             CASE (c >=  58)    : parseFunction[c] = &ParseCharacter()        ' character or operator
  1826.             CASE (c >=  48)    : parseFunction[c] = &ParseNumber()                ' "0-9"
  1827.             CASE (c ==  36)    : parseFunction[c] = &ParseSymbol()                ' "$con" or "$$con
  1828.             CASE (c ==  35)    : parseFunction[c] = &ParseSymbol()                ' "#var" or "##var"
  1829.             CASE (c >=  33)    : parseFunction[c] = &ParseCharacter()        ' character / operator
  1830.             CASE (c ==  32)    : parseFunction[c] = &ParseWhitespace()        ' space chars
  1831.             CASE (c ==   9)    : parseFunction[c] = &ParseWhitespace()        ' tab chars
  1832.             CASE (c <=   8)    : parseFunction[c] = &ParseWhitespace()        ' convert trash to spaces
  1833.         END SELECT
  1834.     NEXT c
  1835. END SUB
  1836. END FUNCTION
  1837. '
  1838. '
  1839. ' ################################
  1840. ' #####  ParseWhitespace ()  #####  parse whitespace characters into a whitespace-string token
  1841. ' ################################
  1842. '
  1843. ' This function collects consecutive whitespace characters starting
  1844. ' at offset in line$.  This function then looks for the whitespace-string
  1845. ' it collected in the 255 element #whitestring$[] array.  If it finds an
  1846. ' identical whitestring, it returns the element # of the matching element
  1847. ' in #whitestring$[].  If it doesn't find a match, it adds the whitestring
  1848. ' to #whitestring$[] and returns the element # of the new whitestring.
  1849. ' If a program is wacko enough to have more than 255 different whitespace
  1850. ' strings, this function will return one of the 255 existing whitespaces.
  1851. '
  1852. ' The 255 whitespace values are designed to be imbedded in whatever token
  1853. ' follows to indicate "leading whitespace".
  1854. '
  1855. FUNCTION  ParseWhitespace (@line$, @offset)
  1856. '
  1857.     token = 0
  1858.     first = offset
  1859.     #whitebyte = 0
  1860. '
  1861.     DO
  1862.         char = line${offset}                                    ' char = next character
  1863.         white = #charsetWhitespace[char]            ' is character whitespace
  1864.         IFZ char THEN RETURN #whitebyte                ' clip trailing whitespace
  1865.         IFZ white THEN EXIT DO                                ' exit unless whitespace
  1866.         INC offset                                                        ' next character on line
  1867.     LOOP
  1868. '
  1869.     token = 0
  1870.     past = offset
  1871.     length = past - first
  1872.     IFZ length THEN RETURN #whitebyte            ' no whitespace
  1873. '
  1874.     whitestring$ = MID$ (line$, first+1, length)
  1875.     IFZ whitestring$ THEN RETURN #whitebyte
  1876. '
  1877.     FOR i = 1 TO #nwhite
  1878.         IF (whitestring$ == #whitestring$[i]) THEN #whitebyte = i : RETURN #whitebyte
  1879.     NEXT i
  1880. '
  1881. ' this whitestring is not yet in whitestring array, so add it
  1882. '
  1883.     IF (#nwhite < #uwhite) THEN
  1884.         INC #nwhite
  1885.         #whitestring$[#nwhite] = whitestring$
  1886.         #whitebyte = #nwhite
  1887.     ELSE
  1888.         #whitebyte = 1            ' no room for another whitestring, so fake one
  1889.     END IF
  1890. '
  1891.     RETURN #whitebyte
  1892. END FUNCTION
  1893. '
  1894. '
  1895. ' ###############################
  1896. ' #####  ParseCharacter ()  #####  parse special characters into the appropriate token
  1897. ' ###############################
  1898. '
  1899. ' This function parses 1 or more consecutive non-alphanumeric
  1900. ' characters starting at offset in line$ into a symbol-token.
  1901. ' Examples include operators ("<>", "<", "<=", "+", "*", "/")
  1902. ' and other language elements ("[" "]" "(" ")" "'"), etc.
  1903. '
  1904. FUNCTION  ParseCharacter (@line$, @offset)
  1905.     STATIC  SUBADDR  parseCharacter[]
  1906.     STATIC  XLONG  characterToken[]
  1907. '
  1908.     IFZ characterToken[] THEN GOSUB Initialize
  1909. '
  1910.     linelength = LEN (line$)
  1911.     char = line${offset}
  1912.     start = offset
  1913.     INC offset
  1914. '
  1915.     token = characterToken[char]                                    ' this one character generates a token
  1916.     IFZ token THEN GOSUB @parseCharacter[char]        ' GOSUB a subroutine to parse this token
  1917.     IF token THEN OutputToken (@token)                        ' add token to program
  1918.     RETURN token
  1919. '
  1920. '
  1921. ' characters that have their own tokens
  1922. '
  1923. SUB Character
  1924.     symbol$ = CHR$ (char)
  1925.     token = AddToken (0, 0, 0, $$KIND_CHARACTER, 0, 0, 0, 0, @symbol$)
  1926.     IF token THEN #token[token].ivalue = char
  1927. END SUB
  1928. '
  1929. '
  1930. ' *************************************************************************
  1931. ' *****  Parse characters that may be part of 1+ character sequences  *****
  1932. ' *************************************************************************
  1933. '
  1934. '
  1935. '
  1936. ' *****  &  *****
  1937. '
  1938. ' &O = prefix for octal literal : &O17777777777 = max-long : &O37777777777 = -1
  1939. ' &H = prefix for hexadecimal literal
  1940. '
  1941. SUB Ampersand
  1942.     value = 0                                            ' value = 0
  1943.     digits = 0                                        ' hex digits
  1944.     char = line${offset}                    ' char after &
  1945. '
  1946.     INC offset                                        ' offset to character after &O or &H prefix
  1947. '
  1948.     SELECT CASE char
  1949.         CASE 'O'
  1950.                 char = line${offset}                ' but only if next character is 0-7
  1951.                 DO WHILE #charsetOctal[char]            ' while character is 0-7
  1952.                     INC digits                                ' count valid hexadecimal digits
  1953.                     INC offset                                ' offset to next hexadecimal digit
  1954.                     SELECT CASE TRUE
  1955.                         CASE ((char >= '0') AND (char <= '7'))    : octal = char - '0'
  1956.                     END SELECT
  1957.                     char = line${offset}                            ' next character
  1958.                     value = (value << 3) OR octal            ' create cumulative hex value
  1959.                 LOOP UNTIL (value AND 0xE0000000)        ' quit before 32-bits overflows
  1960.         CASE 'H'
  1961.                 char = line${offset}                ' but only if next character is 0-9 or A-F
  1962.                 DO WHILE #charsetHexUpper[char]        ' while character is 0-9 or A-F
  1963.                     INC digits                                ' count valid hexadecimal digits
  1964.                     INC offset                                ' offset to next hexadecimal digit
  1965.                     SELECT CASE TRUE
  1966.                         CASE ((char >= '0') AND (char <= '9'))    : hex = char - '0'
  1967.                         CASE ((char >= 'A') AND (char <= 'F'))    : hex = char - 'A' + 10
  1968. '                        CASE ((char >= 'a') AND (char <= 'f'))    : hex = char - 'a' + 10        ' always upper-case in QBasic
  1969.                     END SELECT
  1970.                     char = line${offset}                            ' next character
  1971.                     value = (value << 4) OR hex                ' create cumulative hex value
  1972.                 LOOP UNTIL (value AND 0xF0000000)        ' quit before 32-bits overflows
  1973.     END SELECT
  1974. '
  1975.     IFZ digits THEN
  1976.         offset = start + 1
  1977.         token = AddToken (0, 0, 0, $$KIND_CHARACTER, 0, 0, 0, 0, @"&")
  1978.     ELSE
  1979.         symbol$ = MID$ (line$, start+1, digits+2)
  1980.         token = AddToken (0, 0, 0, $$KIND_LITERAL, $$TYPE_XLONG, 0, 0, 0, @symbol$)
  1981.         IF token THEN #token[token].ivalue = value
  1982.     END IF
  1983. END SUB
  1984. '
  1985. '
  1986. ' *****  "  *****  Literal string  *****
  1987. '
  1988. SUB DoubleQuote
  1989.     scans = offset                ' 0 offset to character after opening double-quote
  1990.     start = offset                ' 1 offset to opening double-quote
  1991.      final = linelength        ' 0 offset to null-terminator
  1992. '
  1993.     IF (scans < final) THEN
  1994.         rawchar = line${scans}
  1995.         DO UNTIL (rawchar = '"')
  1996.             IF (rawchar = '\\') THEN
  1997.                 INC scans
  1998.                 rawchar = line${scans}
  1999.             END IF
  2000.             INC scans
  2001.             rawchar = line${scans}
  2002.         LOOP WHILE (scans < final)
  2003.     END IF
  2004. '
  2005.     IF (scans < final) THEN
  2006.         INC scans
  2007.         offset = scans        ' terminated by " character - normal case
  2008.     ELSE
  2009.         offset = scans        ' terminated by end-of-line null-terminator, not "
  2010.         INC scans
  2011.     END IF
  2012. '
  2013.     lit$ = MID$ (line$, start, (scans-start)) + "\""
  2014.     token = AddToken (0, 0, 0, $$KIND_LITERAL, $$TYPE_STRING, 0, 0, 0, @lit$)
  2015. END SUB
  2016. '
  2017. '
  2018. ' *****  '  *****
  2019. '
  2020. SUB SingleQuote
  2021.     comment$ = MID$ (line$, offset)
  2022.     token = AddToken (0, 0, 0, $$KIND_COMMENT, $$TYPE_STRING, 0, 0, 0, @comment$)
  2023.     offset = linelength
  2024. END SUB
  2025. '
  2026. '
  2027. ' *****  .  *****   .2345e3 (a number)  or  .component of composite
  2028. '
  2029. SUB Dot
  2030.     two = line${offset}
  2031.     SELECT CASE TRUE
  2032.         CASE #charsetNumeric[two]                                ' a number, like .234567
  2033.                     DEC offset
  2034.                     token = ParseNumber (@line$, @offset)
  2035.         CASE #charsetUpperLower[two]                        ' composite element, like .ssn in variable.ssn
  2036.                     DEC offset
  2037.                     token = ParseSymbol (@line$, @offset)
  2038.         CASE ELSE                                                                ' standalone . is a syntax error
  2039.                     token = AddToken (0, 0, 0, $$KIND_CHARACTER, $$TYPE_UBYTE, 0, 0, 0, ".")
  2040.                     IF token THEN #token[token].ivalue = '.'
  2041.                     token = #Q_DOT
  2042.     END SELECT
  2043. END SUB
  2044. '
  2045. '
  2046. ' *****  <  *****   <  <>  <=
  2047. '
  2048. SUB LessThan
  2049.     two = line${offset}                                                ' char after <
  2050.     SELECT CASE two
  2051.         CASE '>'    : token = #Q_NE    : INC offset    ' <>
  2052.         CASE '='    : token = #Q_LE    : INC offset    ' <=
  2053.         CASE ELSE    : token = #Q_LT                                ' <
  2054.     END SELECT
  2055. END SUB
  2056. '
  2057. '
  2058. ' *****  >  *****  >  >=
  2059. '
  2060. SUB GreaterThan
  2061.     two = line${offset}
  2062.     SELECT CASE two
  2063.         CASE '='    : token = #Q_GE    : INC offset        ' >=
  2064.         CASE ELSE    : token = #Q_GT                                    ' >
  2065.     END SELECT
  2066. END SUB
  2067. '
  2068. '
  2069. '
  2070. ' **********************************************************************************
  2071. ' *****  load characterToken[] with tokens for 1-character length tokens only  *****
  2072. ' *****  load parseCharacter[] with addresses of routines to parse characters  *****
  2073. ' **********************************************************************************
  2074. '
  2075. SUB Initialize
  2076.     DIM characterToken[255]
  2077.     DIM parseCharacter[255]
  2078. '
  2079. ' The following single characters get parsed into a token.
  2080. ' In other words, whenever the first character a parse routine
  2081. ' encounters is one of these characters, the single character
  2082. ' always gets parsed into a token.
  2083. '
  2084.     characterToken [ '+' ] = #Q_PLUS
  2085.     characterToken [ '-' ] = #Q_MINUS
  2086.     characterToken [ '*' ] = #Q_MULTIPLY
  2087.     characterToken [ '/' ] = #Q_DIVIDE
  2088.     characterToken [ '^' ] = #Q_POWER
  2089.     characterToken [ '=' ] = #Q_EQ
  2090. '    characterToken [ '&' ] = #Q_AMPERSAND                                ' does QuickBasic support & operator ???
  2091.     characterToken ['\\' ] = #Q_IDIVIDE
  2092.     characterToken [ '(' ] = #Q_LPAREN
  2093.     characterToken [ ')' ] = #Q_RPAREN
  2094.     characterToken [ '[' ] = #Q_LBRAK
  2095.     characterToken [ ']' ] = #Q_RBRAK
  2096.     characterToken [ ':' ] = #Q_COLON
  2097.     characterToken [ ';' ] = #Q_SEMI
  2098.     characterToken [ ',' ] = #Q_COMMA
  2099. '
  2100. ' subroutines to process tokens starting with any character
  2101. '
  2102. '                                                                                                            '  00-32 handled elsewhere
  2103.     parseCharacter [ '!' ] = SUBADDRESS (Character)            '  !
  2104.     parseCharacter [ '"' ] = SUBADDRESS (DoubleQuote)        '  "
  2105.     parseCharacter [ '#' ] = SUBADDRESS (Character)            '  #
  2106.     parseCharacter [ '$' ] = SUBADDRESS (Character)            '  $
  2107.     parseCharacter [ '%' ] = SUBADDRESS (Character)            '  %
  2108.     parseCharacter [ '&' ] = SUBADDRESS (Ampersand)            '  &
  2109.     parseCharacter [ ''' ] = SUBADDRESS (SingleQuote)        '  '
  2110.     parseCharacter [ '.' ] = SUBADDRESS (Dot)                        '  .
  2111. '                                                                                                            '     48-57 handled elsewhere
  2112.     parseCharacter [ '<' ] = SUBADDRESS (LessThan)            '  <  <=  <>
  2113.     parseCharacter [ '>' ] = SUBADDRESS (GreaterThan)        '  >  >=
  2114.     parseCharacter [ '?' ] = SUBADDRESS (Character)            '  ?
  2115.     parseCharacter [ '@' ] = SUBADDRESS (Character)            '  @
  2116. '                                                                                                            '     65-90 handled elsewhere
  2117.     parseCharacter [ '_' ] = SUBADDRESS (Character)            '  _
  2118.     parseCharacter [ '`' ] = SUBADDRESS (Character)            '  `
  2119. '                                                                                                            '     97-122 handled elsewhere
  2120.     parseCharacter [ '{' ] = SUBADDRESS (Character)            '  {
  2121.     parseCharacter [ '|' ] = SUBADDRESS (Character)            '  |
  2122.     parseCharacter [ '}' ] = SUBADDRESS (Character)            '  }
  2123.     parseCharacter [ '~' ] = SUBADDRESS (Character)            '  ~
  2124.     parseCharacter [ 127 ] = SUBADDRESS (Character)            '     CHR$(127)
  2125. '                                                                                                            '     128-255 are white trash
  2126. END SUB
  2127. END FUNCTION
  2128. '
  2129. '
  2130. ' ############################
  2131. ' #####  ParseNumber ()  #####  parse a number into the appropriate number token
  2132. ' ############################
  2133. '
  2134. FUNCTION  ParseNumber (@line$, @offset)
  2135. '
  2136.     enter = offset
  2137.     start = offset
  2138.     specType = XstStringToNumber (@line$, @start, @offset, @rtype, @value$$)
  2139.     vhi = GHIGH (value$$)
  2140.     vlo = GLOW (value$$)
  2141.     value = vlo
  2142. '
  2143.     suffix = line${offset}
  2144.     IF (specType < 0) THEN specType = 0
  2145. '
  2146. ' see if number is followed by a type-suffix
  2147. '
  2148.     IFZ specType THEN
  2149.         SELECT CASE suffix
  2150.             CASE '%'    : specType = $$TYPE_SSHORT    : INC offset
  2151.             CASE '&'    : specType = $$TYPE_SLONG        : INC offset
  2152.             CASE '!'    : specType = $$TYPE_SINGLE    : INC offset
  2153.             CASE '#'    : specType = $$TYPE_DOUBLE    : INC offset
  2154.         END SELECT
  2155.     END IF
  2156. '
  2157.     number$ = MID$ (line$, start+1, offset-start)
  2158. '
  2159. ' if type not specified by anything yet, decide on basis of the value
  2160. '
  2161.     IFZ specType THEN
  2162.         SELECT CASE rtype
  2163.             CASE 0                            : specType = $$SLONG            ' zero
  2164.             CASE $$TYPE_XLONG        : specType = $$SLONG            ' "0x..."
  2165.             CASE $$TYPE_SINGLE    : specType = $$SINGLE            ' "0s..."
  2166.             CASE $$TYPE_GIANT        : specType = MinTypeFromGiant (value$$)
  2167.             CASE $$TYPE_DOUBLE    :    value#   = DMAKE (vhi, vlo)
  2168.                                                         specType = MinTypeFromDouble (value#)
  2169.             CASE ELSE                        : PRINT "ParseNumber() : error" : RETURN ($$FALSE)
  2170.         END SELECT
  2171.     END IF
  2172. '
  2173. ' add the literal number token to the token stream
  2174. '
  2175.     type = specType
  2176.     kind = $$KIND_LITERAL
  2177.     token = AddToken (0, 0, 0, kind, type, 0, 0, 0, @number$)
  2178.     IF token THEN
  2179.         IF (type < $$TYPE_SINGLE) THEN #token[token].ivalue = value$$ ELSE #token[token].fvalue = value#
  2180.     END IF
  2181.     OutputToken (@token)
  2182.     RETURN (token)
  2183. END FUNCTION
  2184. '
  2185. '
  2186. ' ############################
  2187. ' #####  ParseSymbol ()  #####  parse a symbol into the appropriate token
  2188. ' ############################
  2189. '
  2190. FUNCTION  ParseSymbol (@line$, @offset)
  2191. '
  2192. ' collect the symbol
  2193. '
  2194.     token = 0
  2195.     start = offset
  2196.     GetSymbol (@line$, @offset, @symbol$)
  2197.     IFZ symbol$ THEN RETURN token
  2198. '
  2199. ' is symbol a keyword or component of composite
  2200. '
  2201.     firstchar = line${start}
  2202.     afterchar = line${offset}
  2203.     finalchar = line${offset-1}
  2204. '
  2205. ' ??? keyword symbol ???
  2206. '
  2207.     IF (firstchar != '.') THEN
  2208.         token = TestForKeyword (@symbol$)
  2209.         IF token THEN
  2210.             OutputToken (token)
  2211.             RETURN (token)
  2212.         END IF
  2213.     END IF
  2214. '
  2215. ' 1st and 2nd tokens on line need special attention
  2216. '
  2217.     SELECT CASE #tokenptr
  2218.         CASE 0    :    IF ((afterchar == ':') AND (LEN(symbol$) == offset)) THEN        ' label:
  2219.                                 INC offset
  2220.                                 token = AddToken (0, 0, 0, $$KIND_LABEL, $$TYPE_GOADDR, 0, 0, 0, @symbol$)
  2221.                                 OutputToken (@token)
  2222.                                 RETURN (token)
  2223.                             END IF
  2224.         CASE 1    :    IF (#lasttoken == #Q_TYPE) THEN
  2225.                                 IF #charsetUpperLower[firstchar] THEN
  2226.                                     IF #charsetUpperLowerNumeric[finalchar] THEN
  2227.                                         token = AddToken (0, 0, 0, $$KIND_TYPE, 0, 0, 0, 0, @symbol$)
  2228.                                         OutputToken (@token)
  2229.                                         RETURN (token)
  2230.                                     END IF
  2231.                                 END IF
  2232.                             END IF
  2233.     END SELECT
  2234. '
  2235. ' certain symbols are interpreted differently if following certain tokens
  2236. '
  2237.     SELECT CASE #lasttoken
  2238.         CASE #Q_GOTO                                                                                ' GOTO label
  2239.             token = AddToken (0, 0, 0, $$KIND_LABEL, $$TYPE_GOADDR, 0, 0, 0, @symbol$)
  2240.             OutputToken (@token)
  2241.             RETURN (token)
  2242.         CASE #Q_GOSUB, #Q_SUB                                                                ' SUB subname or GOSUB subname
  2243.             token = AddToken (0, 0, 0, $$KIND_LABEL, $$TYPE_SUBADDR, 0, 0, 0, @symbol$)
  2244.             OutputToken (@token)
  2245.             RETURN (token)
  2246.         CASE #Q_LPAREN
  2247.             SELECT CASE #backtoken
  2248.                 CASE T_GOADDRESS                                                                ' GOADDRESS (label)
  2249.                     token = AddToken (0, 0, 0, $$KIND_LABEL, $$TYPE_GOADDR, 0, 0, 0, @symbol$)
  2250.                     OutputToken (@token)
  2251.                     RETURN (token)
  2252.                 CASE T_SUBADDRESS                                                                ' SUBADDRESS (subname)
  2253.                     token = AddToken (0, 0, 0, $$KIND_LABEL, $$TYPE_SUBADDR, 0, 0, 0, @symbol$)
  2254.                     OutputToken (@token)
  2255.                     RETURN (token)
  2256.             END SELECT
  2257.         CASE ELSE
  2258.     END SELECT
  2259. '
  2260. ' symbols that begin with certain characters require special attention
  2261. '
  2262. ' .components of composites
  2263. '
  2264.     IF (firstchar = '.') THEN                                                            ' .COMPONENT name
  2265.         token = AddToken (0, 0, 0, $$KIND_SYMBOL, 0, 0, 0, 0, @symbol$)
  2266.         OutputToken (@token)
  2267.         RETURN (token)
  2268.     END IF
  2269. '
  2270. ' normal symbols can have type suffix characters
  2271. '
  2272.     SELECT CASE afterchar
  2273.         CASE '@'    :    symbol$ = symbol$ + "@"
  2274.                                 type = $$SBYTE
  2275.                                 INC offset
  2276.         CASE '%'    :    symbol$ = symbol$ + "%"
  2277.                                 type = $$SSHORT
  2278.                                 INC offset
  2279.         CASE '&'    :    symbol$ = symbol$ + "&"
  2280.                                 type = $$SLONG
  2281.                                 INC offset
  2282.         CASE '!'    :    symbol$ = symbol$ + "!"
  2283.                                 type = $$SINGLE
  2284.                                 INC offset
  2285.         CASE '#'    :    symbol$ = symbol$ + "#"
  2286.                                 type = $$DOUBLE
  2287.                                 INC offset
  2288.         CASE '$'    :    symbol$ = symbol$ + "$"
  2289.                                 type = $$STRING
  2290.                                 INC offset
  2291.         CASE ELSE    :    type = 0
  2292.     END SELECT
  2293. '
  2294. ' see what follows trailing spaces/tabs
  2295. '
  2296.     sx = 0
  2297.     test = line${offset + sx}
  2298.     DO WHILE (#charsetSpaceTab[test])
  2299.         INC sx
  2300.         test = line${offset + sx}
  2301.     LOOP
  2302. '
  2303. ' see if this is an array or function symbol
  2304. '
  2305.     SELECT CASE test
  2306.         CASE '('    : kind = $$KIND_FUNCTION
  2307.         CASE '['    : kind = $$KIND_ARRAY
  2308.         CASE ELSE    : kind = $$KIND_VARIABLE
  2309.     END SELECT
  2310. '
  2311.     token = AddToken (0, 0, 0, kind, type, scope, 0, 0, @symbol$)
  2312.     OutputToken (@token)
  2313.     RETURN (token)
  2314. END FUNCTION
  2315. '
  2316. '
  2317. ' ##########################
  2318. ' #####  GetSymbol ()  #####
  2319. ' ##########################
  2320. '
  2321. FUNCTION  GetSymbol (line$, offset, symbol$)
  2322. '
  2323.     start = offset
  2324.     char = line${offset}
  2325.     IF (char == '.') THEN INC offset : char = line${offset}        ' .component symbol
  2326. '
  2327.     DO WHILE (#charsetSymbolInner[char])                                                ' TRUE while A-Z, a-z, 0-9, "_"
  2328.         INC offset
  2329.         char = line${offset}
  2330.     LOOP
  2331. '
  2332.     symbol$ = MID$ (line$, start+1, offset-start)
  2333. END FUNCTION
  2334. '
  2335. '
  2336. ' ############################
  2337. ' #####  OutputToken ()  #####  parse a symbol into the appropriate token
  2338. ' ############################
  2339. '
  2340. FUNCTION  OutputToken (token)
  2341. '
  2342.     #backtoken = #lasttoken
  2343.     #lasttoken = token
  2344. '
  2345.     IF (#nlinetoken > #ulinetoken) THEN
  2346.         #ulinetoken = #ulinetoken + 256
  2347.         REDIM #line[#ulinetoken]
  2348.     END IF
  2349. '
  2350.     IF (#whitebyte > 255) THEN #whitebyte = 1            ' disaster catcher
  2351.     token = (#whitebyte << 24) + token                        ' put whitebyte in token
  2352.     #line[#nlinetoken] = token                                        ' add complete token to line of tokens
  2353.     INC #nlinetoken                                                                ' next token in this line of tokens
  2354.     #whitebyte = 0                                                                ' whitestring output so cancel it
  2355. '
  2356.     IF #print THEN PRINT " "; HEX$(token,8);
  2357. END FUNCTION
  2358. '
  2359. '
  2360. ' ###############################
  2361. ' #####  TestForKeyword ()  #####
  2362. ' ###############################
  2363. '
  2364. FUNCTION  TestForKeyword (string$)
  2365. '
  2366.     token = 0
  2367.     IFZ string$ THEN RETURN token
  2368. '
  2369.     firstchar = string${0}
  2370.     IF (firstchar = '_') THEN RETURN token
  2371. '
  2372.     length = LEN (string$)
  2373.     upper = length - 1
  2374.     hash = 0
  2375. '
  2376.     FOR i = 0 TO upper                                                ' for all bytes in string
  2377.         hash = hash + #hx[string${i}]                        ' add hash for that byte
  2378.     NEXT i                                                                        ' next byte in string
  2379. '
  2380.     hash = hash AND 0x000000FF                                ' clip hash to byte
  2381.     token = 0
  2382. '
  2383. ' is symbol a QBasic keyword ???
  2384. '
  2385.     FOR t = #qatoken TO #qztoken
  2386.         IF (hash == #token[t].hash) THEN
  2387.             IF (#string$[#token[t].string] == string$) THEN        ' found keyword
  2388.                 token = t
  2389.                 EXIT FOR
  2390.             END IF
  2391.         END IF
  2392.     NEXT t
  2393.     RETURN token
  2394. END FUNCTION
  2395. '
  2396. '
  2397. ' #################################
  2398. ' #####  MinTypeFromGiant ()  #####
  2399. ' #################################
  2400. '
  2401. FUNCTION  MinTypeFromGiant (v$$)
  2402. '
  2403.     SELECT CASE TRUE
  2404.         CASE ((v$$ >= $$MIN_USHORT) AND (v$$ <= $$MAX_USHORT))    : rt = $$USHORT
  2405.         CASE ((v$$ >= $$MIN_SSHORT) AND (v$$ <= $$MAX_SSHORT))    : rt = $$SSHORT
  2406.         CASE ((v$$ >= $$MIN_SLONG)  AND (v$$ <= $$MAX_SLONG))        : rt = $$SLONG
  2407.         CASE ELSE                                                                                                : rt = $$GIANT
  2408.     END SELECT
  2409.     RETURN (rt)
  2410. END FUNCTION
  2411. '
  2412. '
  2413. ' ##################################
  2414. ' #####  MinTypeFromDouble ()  #####
  2415. ' ##################################
  2416. '
  2417. FUNCTION  MinTypeFromDouble (value#)
  2418. '
  2419.     IF (value# < 0) THEN value# = -value#
  2420.     minSingleExponent# = 0s00800000
  2421.     maxSingleExponent# = 0s7F000000
  2422.     IF (value# < minSingleExponent#) THEN RETURN ($$TYPE_DOUBLE)
  2423.     IF (value# > maxSingleExponent#) THEN RETURN ($$TYPE_DOUBLE)
  2424.     svalue! = value#
  2425.     dvalue# = svalue!
  2426.     IF (value# == dvalue#) THEN RETURN ($$TYPE_SINGLE)
  2427.     RETURN ($$TYPE_DOUBLE)
  2428. END FUNCTION
  2429. '
  2430. '
  2431. ' ###########################
  2432. ' #####  AddKeyword ()  #####
  2433. ' ###########################
  2434. '
  2435. FUNCTION  AddKeyword (translate, function, scope, kind, type, atype1, atype2, atype3, string$)
  2436. '
  2437.     ntoken = 0                                                                ' 0 means failure
  2438.     IFZ string$ THEN RETURN ntoken                        ' empty string is no keyword
  2439. '
  2440.     IF (kind AND $$KIND_QBASIC) THEN qbasic = $$TRUE ELSE qbasic = $$FALSE
  2441.     IF (kind AND $$KIND_XBASIC) THEN xbasic = $$TRUE ELSE xbasic = $$FALSE
  2442. '
  2443.     length = LEN (string$)                                        ' length of string
  2444.     upper = length - 1                                                ' upper bound
  2445.     hash = 0                                                                    ' initialize
  2446. '
  2447.     FOR i = 0 TO upper                                                ' for all bytes in string
  2448.         hash = hash + #hx[string${i}]                        ' add hash for that byte
  2449.     NEXT i                                                                        ' next byte in string
  2450. '
  2451.     hash = hash AND 0x000000FF                                ' clip hash to byte
  2452.     hashtoken = #hash[hash]                                        ' see if any tokens with this hash exist yet
  2453.     INC #nstring                                                            ' store string in next string-number
  2454.     INC #ntoken                                                                ' store token in next token-number
  2455. '
  2456.     SELECT CASE #pass
  2457.         CASE 1    : GOSUB PassOne                                    ' establish token and string
  2458.         CASE 2    : GOSUB PassTwo                                    ' add translate token and string
  2459.     END SELECT
  2460.     RETURN ntoken                                                            '
  2461. '
  2462. '
  2463. ' *********************
  2464. ' *****  PassOne  *****  update hash-links in tokens
  2465. ' *********************
  2466. '
  2467. SUB PassOne
  2468.     IFZ hashtoken THEN                                                ' first string with this hash value
  2469.         #hash[hash] = #ntoken                                        ' remember first token with this hash
  2470.         hashback = #ntoken                                            ' this is also the last string with this hash
  2471.         hashnext = 0                                                        ' no more strings with this hash value yet
  2472.     ELSE                                                                            '
  2473.         last = #token[hashtoken].hashback                ' last contains last entry with this hash
  2474.         next = #token[hashtoken].hashnext                ' next contains second entry with this hash
  2475.         IF #token[last].hashnext THEN STOP            ' error if last token already points forward
  2476.         #token[hashtoken].hashback = #ntoken        ' point first token with this hash at this one
  2477.         #token[last].hashnext = #ntoken                    ' last token with this hash becomes next-to-last
  2478.         hashback = last                                                    ' previous token with this hash value
  2479.         hashnext = 0                                                        ' last token with this hash value
  2480.     END IF
  2481. '
  2482. ' add token information and symbol string
  2483. '
  2484.     #string$[#nstring] = string$                            ' add new symbol to string table
  2485. '
  2486.     #token[#ntoken].translate = translate            ' token in other language - QBasic or XBasic
  2487.     #token[#ntoken].function = function                ' function this token is defined in
  2488.     #token[#ntoken].string = #nstring                    ' string that contains this symbol
  2489.     #token[#ntoken].length = length                        ' length of this token symbol
  2490.     #token[#ntoken].token = #ntoken                        ' token number of this token
  2491.     #token[#ntoken].scope = scope                            ' scope of token
  2492.     #token[#ntoken].kind = kind                                ' kind of token
  2493.     #token[#ntoken].type = type                                ' type of token
  2494.     #token[#ntoken].hash = hash                                ' hash of token
  2495.     #token[#ntoken].hashback = hashback                ' previous token with this hash
  2496.     #token[#ntoken].hashnext = hashnext                ' next token with this hash
  2497.     #token[#ntoken].akind[0] = 0                            ' kind of argument 0
  2498.     #token[#ntoken].akind[1] = 0                            ' kind of argument 1
  2499.     #token[#ntoken].akind[2] = 0                            ' kind of argument 2
  2500.     #token[#ntoken].atype[0] = atype1                    ' type of argument 0
  2501.     #token[#ntoken].atype[1] = atype2                    ' type of argument 1
  2502.     #token[#ntoken].atype[2] = atype3                    ' type of argument 2
  2503.     #token[#ntoken].first = 0                                    '
  2504.     #token[#ntoken].final = 0                                    '
  2505.     #token[#ntoken].ivalue = 0$$                            '
  2506.     #token[#ntoken].fvalue = 0.00#                        '
  2507.     ntoken = #ntoken
  2508. END SUB
  2509. '
  2510. '
  2511. ' *********************
  2512. ' *****  PassTwo  *****  update hash-links in tokens
  2513. ' *********************
  2514. '
  2515. SUB PassTwo
  2516.     IF (#string$[#token[#ntoken].string] != string$) THEN PRINT "#####  disaster  #####" : EXIT SUB
  2517.     IF (#token[#ntoken].function != function) THEN PRINT "#####  disaster  #####" : EXIT SUB
  2518.     IF (#token[#ntoken].length != length) THEN PRINT "#####  disaster  #####" : EXIT SUB
  2519.     IF (#token[#ntoken].token != #ntoken) THEN PRINT "#####  disaster  #####" : EXIT SUB
  2520.     IF (#token[#ntoken].scope != scope) THEN PRINT "#####  disaster  #####" : EXIT SUB
  2521.     IF (#token[#ntoken].kind != kind) THEN PRINT "#####  disaster  #####" : EXIT SUB
  2522.     IF (#token[#ntoken].type != type) THEN PRINT "#####  disaster  #####" : EXIT SUB
  2523. '
  2524.     #token[#ntoken].translate = translate
  2525.     ntoken = #ntoken
  2526. END SUB
  2527. END FUNCTION
  2528. '
  2529. '
  2530. ' ##########################
  2531. ' #####  FindToken ()  #####
  2532. ' ##########################
  2533. '
  2534. FUNCTION  FindToken (@match[], function, scope, kind, type, atype1, atype2, atype3, string$)
  2535. '
  2536.     ntoken = 0                                                                ' token not found
  2537.     DIM match[]                                                                ' no matches found yet
  2538.     IFZ string$ THEN RETURN ntoken                        ' empty symbol is no symbol
  2539. '
  2540.     IF (kind AND $$KIND_QBASIC) THEN qbasic = $$TRUE ELSE qbasic = $$FALSE
  2541.     IF (kind AND $$KIND_XBASIC) THEN xbasic = $$TRUE ELSE xbasic = $$FALSE
  2542. '
  2543.     length = LEN (string$)                                        ' length of string in bytes
  2544.     upper = length - 1                                                ' upper bound of string
  2545.     hash = 0                                                                    ' initialize hash
  2546. '
  2547.     FOR i = 0 TO upper                                                ' for all bytes in string
  2548.         hash = hash + #hx[string${i}]                        ' add hash for that byte
  2549.     NEXT i
  2550. '
  2551.     hash = hash AND 0x000000FF                                ' clip hash to byte value
  2552. '
  2553.     ntoken = #hash[hash]                                            ' first entry with this hash
  2554.     IFZ ntoken THEN RETURN $$FALSE                        ' no symbol with this hash
  2555. '
  2556. ' check all symbols with this hash for a match
  2557. '
  2558. '
  2559.     nmatch = 0                                                                ' number of matches
  2560.     umatch = 15                                                                ' maximum match number
  2561.     DIM match[umatch]                                                    ' upper bound of match[]
  2562. '
  2563.     DO
  2564.         symbol = #token[ntoken].string                                        ' entry in string table
  2565.         IF (symbol$ == #string$[string]) THEN                            ' symbols match
  2566.             IF (function == #token[ntoken].function) THEN        ' functions match
  2567.                 IF (nmatch > umatch) THEN                                            ' make more room
  2568.                     umatch = umatch + 16                                                ' 16 more now
  2569.                     REDIM match[umatch]                                                    ' make room
  2570.                 END IF                                                                                '
  2571.                 match[nmatch] = ntoken                                                ' return the token
  2572.                 INC nmatch                                                                        ' next match number
  2573.             END IF                                                                                    '
  2574.         END IF
  2575.         ntoken = #token[ntoken].hashnext                                    ' next token with same hash
  2576.     LOOP WHILE ntoken                                                                        ' no more tokens with this hash
  2577. END FUNCTION
  2578. '
  2579. '
  2580. ' #########################
  2581. ' #####  AddToken ()  #####
  2582. ' #########################
  2583. '
  2584. FUNCTION  AddToken (@token, function, scope, kind, type, atype1, atype2, atype3, string$)
  2585. '
  2586.     ntoken = 0                                                                ' token not added
  2587.     IFZ string$ THEN RETURN ntoken                        ' empty string is no symbol
  2588. '
  2589.     IF (kind AND $$KIND_QBASIC) THEN qbasic = $$TRUE ELSE qbasic = $$FALSE
  2590.     IF (kind AND $$KIND_XBASIC) THEN xbasic = $$TRUE ELSE xbasic = $$FALSE
  2591. '
  2592.     length = LEN (string$)                                        ' length of string in bytes
  2593.     upper = length - 1                                                ' upper bound of string
  2594.     hash = 0                                                                    ' initialize hash
  2595. '
  2596.     FOR i = 0 TO upper                                                ' for all bytes in string
  2597.         hash = hash + #hx[string${i}]                        ' add hash for that byte
  2598.     NEXT i                                                                        ' next byte in string
  2599. '
  2600.     hash = hash AND 0x000000FF                                ' clip hash to byte
  2601.     hashtoken = #hash[hash]                                        ' see if any tokens with this hash exist yet
  2602.     ntoken = 0                                                                ' no token yet
  2603. '
  2604. ' If no token has this hash, this must be a new token, and
  2605. ' therefore this token is definitely added to symbol-table.
  2606. '
  2607.     IFZ hashtoken THEN GOSUB NewHash
  2608.     IF ntoken THEN RETURN ntoken
  2609. '
  2610. ' If token already exists, return the existing token
  2611. '
  2612.     GOSUB FindToken
  2613.     IF ntoken THEN RETURN ntoken
  2614. '
  2615. ' otherwise create and return a new token
  2616. '
  2617.     GOSUB AddToken
  2618.     RETURN ntoken
  2619. '
  2620. '
  2621. ' *********************
  2622. ' *****  NewHash  *****  token must be new because hash-value is zero
  2623. ' *********************
  2624. '
  2625. SUB NewHash
  2626.     ntoken = 0
  2627.     INC #ntoken                                                            ' store token in next token-number
  2628.     INC #nstring                                                        ' store string in next string-number
  2629.     #hash[hash] = #ntoken                                        ' remember base-token with this hash
  2630.     #token[#ntoken].hashback = #ntoken            ' this is also the last string with this hash
  2631.     #token[#ntoken].hashnext = #ntoken            ' this is also the next string with this hash
  2632. '
  2633.     #token[#ntoken].hash = hash                            '
  2634.     #token[#ntoken].kind = kind                            '
  2635.     #token[#ntoken].type = type                            '
  2636.     #token[#ntoken].scope = scope                        '
  2637.     #token[#ntoken].token = #ntoken                    '
  2638.     #token[#ntoken].length = length                    '
  2639.     #token[#ntoken].string = #nstring                '
  2640.     #token[#ntoken].function = function            '
  2641.     #token[#ntoken].atype[1] = atype1                '
  2642.     #token[#ntoken].atype[2] = atype2                '
  2643.     #token[#ntoken].atype[3] = atype3                '
  2644.     #string$[#nstring] = string$                        '
  2645.     ntoken = #ntoken                                                ' return token number of this new token
  2646.     token = ntoken
  2647. END SUB
  2648. '
  2649. '
  2650. ' ***********************
  2651. ' *****  FindToken  *****
  2652. ' ***********************
  2653. '
  2654. SUB FindToken
  2655.     ntoken = 0
  2656.     last = #token[hashtoken].hashback                ' last contains last entry with this hash
  2657.     next = #token[hashtoken].hashnext                ' next contains second entry with this hash
  2658.     token = last                                                        ' start with last token with this hash value
  2659. '
  2660.     DO
  2661.         IF (kind == #token[token].kind) THEN
  2662.             IF (hash == #token[token].hash) THEN
  2663.                 IF (scope == #token[token].scope) THEN
  2664.                     IF (length == #token[token].length) THEN
  2665.                         IF (string$ == #string$[#token[token].string]) THEN            ' found token
  2666.                             ntoken = token
  2667.                             EXIT DO
  2668.                         END IF
  2669.                     END IF
  2670.                 END IF
  2671.             END IF
  2672.         END IF
  2673.         IF (token == hashtoken) THEN EXIT DO    ' no more tokens with this hash value
  2674.         token = #token[token].hashback                ' next token to test
  2675.     LOOP
  2676. END SUB
  2677. '
  2678. '
  2679. ' **********************
  2680. ' *****  AddToken  *****
  2681. ' **********************
  2682. '
  2683. SUB AddToken
  2684.     ntoken = 0                                                            ' new token not added yet
  2685.     INC #ntoken                                                            ' store token in next token-number
  2686.     INC #nstring                                                        ' store string in next string-number
  2687.     last = #token[hashtoken].hashback                ' last contains last entry with this hash
  2688. '
  2689.     #token[#ntoken].hashback = last                    ' new last-entry points back to old last-entry
  2690.     #token[#ntoken].hashnext = hashtoken        ' new last-entry points back at first-entry
  2691.     #token[last].hashnext = #ntoken                    ' old last-entry points next to new last-entry
  2692.     #token[hashtoken].hashback = #ntoken        ' the base-entry points back at new last-entry
  2693. '
  2694.     #hash[hash] = #ntoken                                        ' remember first token with this hash
  2695.     #token[#ntoken].hash = hash                            '
  2696.     #token[#ntoken].kind = kind                            '
  2697.     #token[#ntoken].type = type                            '
  2698.     #token[#ntoken].scope = scope                        '
  2699.     #token[#ntoken].token = #ntoken                    '
  2700.     #token[#ntoken].length = length                    '
  2701.     #token[#ntoken].string = #nstring                '
  2702.     #token[#ntoken].function = function            '
  2703.     #token[#ntoken].atype[1] = atype1                '
  2704.     #token[#ntoken].atype[2] = atype2                '
  2705.     #token[#ntoken].atype[3] = atype3                '
  2706.     #string$[#nstring] = string$                        '
  2707.     ntoken = #ntoken                                                ' return token number of this new token
  2708.     token = ntoken
  2709. END SUB
  2710. END FUNCTION
  2711. '
  2712. '
  2713. ' #############################
  2714. ' #####  OutputXBasic ()  #####
  2715. ' #############################
  2716. '
  2717. FUNCTION  OutputXBasic (text$[])
  2718.  
  2719.     IFZ text$[] THEN RETURN
  2720.     upper = UBOUND (text$[])
  2721.     lines = upper + 1
  2722. '
  2723.     new = #xline + lines
  2724. '
  2725.     IF (new > (#xuline - 256)) THEN
  2726.         #xuline = #xuline + 1024
  2727.         REDIM #xbasic$[#xuline]
  2728.     END IF
  2729. '
  2730.     FOR i = 0 TO upper
  2731.         #xbasic$[#xline] = text$[i]
  2732.         INC #xline
  2733.     NEXT i
  2734. END FUNCTION
  2735. '
  2736. '
  2737. ' ################################
  2738. ' #####  TokenRestOfLine ()  #####
  2739. ' ################################
  2740. '
  2741. FUNCTION  TokenRestOfLine ()
  2742. '
  2743. ' xxxxx
  2744. '
  2745. END FUNCTION
  2746. '
  2747. '
  2748. ' ############################
  2749. ' #####  PrintTokens ()  #####
  2750. ' ############################
  2751. '
  2752. FUNCTION  PrintTokens ()
  2753. '
  2754.     FOR i = 0 TO #ntoken+1
  2755.         IFZ (i AND 0x000F) THEN PRINT " tok# trantok# hash back next func     kind datatype scope    integer-value length  symbol-string    translate-symbol"
  2756.         PRINT " ";
  2757.         PRINT HEX$(#token[i].token,4);;
  2758.         PRINT HEX$(#token[i].translate,8);;
  2759.         PRINT HEX$(#token[i].hash,4);;
  2760.         PRINT HEX$(#token[i].hashback,4);;
  2761.         PRINT HEX$(#token[i].hashnext,4);;
  2762.         PRINT HEX$(#token[i].function,4);;
  2763.         PRINT HEX$(#token[i].kind,8);;
  2764.         PRINT HEX$(#token[i].type,8);;
  2765.         PRINT HEX$(#token[i].scope,5);;
  2766.         PRINT HEX$(#token[i].ivalue,16);;
  2767. '        PRINT HEX$(#token[i].fvalue,16);;
  2768.         PRINT HEX$(#token[i].length,6);;;
  2769.         PRINT FORMAT$("<<<<<<<<<<<<<<<<", #string$[#token[i].string]);;
  2770. '
  2771.         translate = #token[i].translate
  2772.         IF translate THEN PRINT #string$[#token[translate].string] ELSE PRINT
  2773.     NEXT i
  2774. END FUNCTION
  2775. '
  2776. '
  2777. ' ##########################
  2778. ' #####  PrintHash ()  #####
  2779. ' ##########################
  2780. '
  2781. FUNCTION  PrintHash ()
  2782. '
  2783.     FOR i = 0 TO 255
  2784.         PRINT HEX$(i,2); " : ";
  2785.         n = #hash[i]
  2786.         DO WHILE n
  2787.             PRINT HEX$(n,4);;
  2788.             n = #token[n].hashnext
  2789.         LOOP
  2790.         PRINT
  2791.     NEXT i
  2792. END FUNCTION
  2793. '
  2794. '
  2795. ' ##########################
  2796. ' #####  Terminate ()  #####
  2797. ' ##########################
  2798. '
  2799. FUNCTION  Terminate ()
  2800. '
  2801. ' xxxxx
  2802. '
  2803. END FUNCTION
  2804. END PROGRAM
  2805.