aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XMREngine/MMRScriptTokenize.cs
blob: a767dcf24e367ba1486459743bd696c2d6b4a12e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
/*
 * Copyright (c) Contributors, http://opensimulator.org/
 * See CONTRIBUTORS.TXT for a full list of copyright holders.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSimulator Project nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * @brief Parse raw source file string into token list.
 *
 * Usage:
 *
 *    emsg = some function to output error messages to
 *    source = string containing entire source file
 *
 *    TokenBegin tokenBegin = TokenBegin.Construct (emsg, source);
 *
 *    tokenBegin = null: tokenizing error
 *                 else: first (dummy) token in file
 *                       the rest are chained by nextToken,prevToken
 *                       final token is always a (dummy) TokenEnd
 */

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;

using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;

namespace OpenSim.Region.ScriptEngine.XMREngine {

    public delegate void TokenErrorMessage (Token token, string message);

    /**
     * @brief base class for all tokens
     */
    public class Token {
        public static readonly int MAX_NAME_LEN = 255;
        public static readonly int MAX_STRING_LEN = 4096;

        public Token nextToken;
        public Token prevToken;
        public bool  nr2l;

        // used for error message printing
        public TokenErrorMessage emsg;
        public string file = "";
        public int line;
        public int posn;
        public Token copiedFrom;

        /**
         * @brief construct a token coming directly from a source file
         * @param emsg = object that error messages get sent to
         * @param file = source file name (or "" if none)
         * @param line = source file line number
         * @param posn = token's position within that source line
         */
        public Token (TokenErrorMessage emsg, string file, int line, int posn)
        {
            this.emsg = emsg;
            this.file = file;
            this.line = line;
            this.posn = posn;
        }

        /**
         * @brief construct a token with same error message parameters
         * @param original = original token to create from
         */
        public Token (Token original)
        {
            if (original != null) {
                this.emsg = original.emsg;
                this.file = original.file;
                this.line = original.line;
                this.posn = original.posn;
                this.nr2l = original.nr2l;
            }
        }

        /**
         * @brief output an error message associated with this token
         *        sends the message to the token's error object
         * @param message = error message string
         */
        public void ErrorMsg (string message)
        {
            if (emsg != null) {
                emsg (this, message);
            }
        }

        /*
         * Generate a unique string (for use in CIL label names, etc)
         */
        public string Unique
        {
            get { return file + "_" + line + "_" + posn; }
        }

        /*
         * Generate source location string (for use in error messages)
         */
        public string SrcLoc
        {
            get {
                string loc = file + "(" + line + "," + posn + ")";
                if (copiedFrom == null) return loc;
                string fromLoc = copiedFrom.SrcLoc;
                if (fromLoc.StartsWith (loc)) return fromLoc;
                return loc + ":" + fromLoc;
            }
        }

        /*
         * Used in generic instantiation to copy token.
         * Only valid for parsing tokens, not reduction tokens 
         * because it is a shallow copy.
         */
        public Token CopyToken (Token src)
        {
            Token t = (Token)this.MemberwiseClone ();
            t.file  = src.file;
            t.line  = src.line;
            t.posn  = src.posn;
            t.copiedFrom = this;
            return t;
        }

        /*
         * Generate debugging string - should look like source code.
         */
        public virtual void DebString (StringBuilder sb)
        {
            sb.Append (this.ToString ());
        }
    }


    /**
     * @brief token that begins a source file
     *        Along with TokenEnd, it keeps insertion/removal of intermediate tokens
     *        simple as the intermediate tokens always have non-null nextToken,prevToken.
     */
    public class TokenBegin : Token {

        public int expiryDays = Int32.MaxValue;  // has seen 'XMROption expiryDays;'

        private class Options {
            public bool arrays;         // has seen 'XMROption arrays;'
            public bool advFlowCtl;     // has seen 'XMROption advFlowCtl;'
            public bool tryCatch;       // has seen 'XMROption tryCatch;'
            public bool objects;        // has seen 'XMROption objects;'
            public bool chars;          // has seen 'XMROption chars;'
            public bool noRightToLeft;  // has seen 'XMROption noRightToLeft;'
            public bool dollarsigns;    // has seen 'XMROption dollarsigns;'
        }

        private bool youveAnError;      // there was some error tokenizing
        private int bolIdx;             // index in 'source' at begining of current line
        private int lineNo;             // current line in source file, starting at 0
        private string filNam;          // current source file name
        private string source;          // the whole script source code
        private Token lastToken;        // last token created so far
        private string cameFrom;        // where the source came from
        private TextWriter saveSource;  // save copy of source here (or null)
        private Options options = new Options ();

        /**
         * @brief convert a source file in the form of a string
         *        to a list of raw tokens
         * @param cameFrom = where the source came from
         * @param emsg     = where to output messages to
         * @param source   = whole source file contents
         * @returns null: conversion error, message already output
         *          else: list of tokens, starting with TokenBegin, ending with TokenEnd.
         */
        public static TokenBegin Construct (string cameFrom, TextWriter saveSource, TokenErrorMessage emsg, string source, out string sourceHash)
        {
            sourceHash = null;

            /*
             * Now do the tokenization.
             */
            TokenBegin tokenBegin = new TokenBegin (emsg, "", 0, 0);
            tokenBegin.cameFrom   = cameFrom;
            tokenBegin.saveSource = saveSource;
            tokenBegin.lastToken  = tokenBegin;
            tokenBegin.source     = source;
            tokenBegin.filNam     = cameFrom;
            if (saveSource != null) saveSource.WriteLine (source);
            tokenBegin.Tokenize ();
            if (tokenBegin.youveAnError) return null;
            tokenBegin.AppendToken (new TokenEnd (emsg, tokenBegin.filNam, ++ tokenBegin.lineNo, 0));

            /*
             * Return source hash so caller can know if source changes.
             */
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create ();
            byte[] hashBytes = md5.ComputeHash (new TokenStream (tokenBegin));
            int hashBytesLen = hashBytes.Length;
            StringBuilder sb = new StringBuilder (hashBytesLen * 2);
            for (int i = 0; i < hashBytesLen; i ++) {
                sb.Append (hashBytes[i].ToString ("X2"));
            }
            sourceHash = sb.ToString ();
            if (saveSource != null) {
                saveSource.WriteLine ("");
                saveSource.WriteLine ("********************************************************************************");
                saveSource.WriteLine ("****  source hash: " + sourceHash);
                saveSource.WriteLine ("********************************************************************************");
            }

            return tokenBegin;
        }

        private TokenBegin (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }

        /*
         * Stream consisting of all the tokens.
         * Null delimeters between the tokens.
         * Used for creating the source hash.
         */
        private class TokenStream : Stream {
            private Token curTok;
            private bool delim;
            private byte[] curBuf;
            private int curOfs;
            private int curLen;

            public TokenStream (Token t)
            {
                curTok = t;
            }

            public override bool CanRead  { get { return true;  } }
            public override bool CanSeek  { get { return false; } }
            public override bool CanWrite { get { return false; } }
            public override long Length   { get { return 0; } }
            public override long Position { get { return 0; } set { } }

            public override void Write (byte[] buffer, int offset, int count) { }
            public override void Flush () { }
            public override long Seek (long offset, SeekOrigin origin) { return 0; }
            public override void SetLength (long value) { }

            public override int Read (byte[] buffer, int offset, int count)
            {
                int len, total;
                for (total = 0; total < count; total += len) {
                    while ((len = curLen - curOfs) <= 0) {
                        if (curTok is TokenEnd) goto done;
                        curTok = curTok.nextToken;
                        if (curTok is TokenEnd) goto done;
                        curBuf = System.Text.Encoding.UTF8.GetBytes (curTok.ToString ());
                        curOfs = 0;
                        curLen = curBuf.Length;
                        delim  = true;
                    }
                    if (delim) {
                        buffer[offset+total] = 0;
                        delim = false;
                        len   = 1;
                    } else {
                        if (len > count - total) len = count - total;
                        Array.Copy (curBuf, curOfs, buffer, offset + total, len);
                        curOfs += len;
                    }
                }
              done:
                return total;
            }
        }

        /*
         * Produces raw token stream: names, numbers, strings, keywords/delimeters.
         * @param this.source = whole source file in one string
         * @returns this.nextToken = filled in with tokens
         *          this.youveAnError = true: some tokenizing error
         *                             false: successful
         */
        private void Tokenize ()
        {
            bolIdx = 0;
            lineNo = 0;
            for (int i = 0; i < source.Length; i ++) {
                char c = source[i];
                if (c == '\n') {

                    /*
                     * Increment source line number and set char index of beg of next line.
                     */
                    lineNo ++;
                    bolIdx = i + 1;

                    /*
                     * Check for '#' lineno filename newline
                     * lineno is line number of next line in file
                     * If found, save values and remove tokens from stream
                     */
                    if ((lastToken is TokenStr) &&
                        (lastToken.prevToken is TokenInt) &&
                        (lastToken.prevToken.prevToken is TokenKwHash)) {
                        filNam = ((TokenStr)lastToken).val;
                        lineNo = ((TokenInt)lastToken.prevToken).val;
                        lastToken = lastToken.prevToken.prevToken.prevToken;
                        lastToken.nextToken = null;
                    }
                    continue;
                }

                /*
                 * Skip over whitespace.
                 */
                if (c <= ' ') continue;

                /*
                 * Skip over comments.
                 */
                if ((i + 2 <= source.Length) && source.Substring (i, 2).Equals ("//")) {
                    while ((i < source.Length) && (source[i] != '\n')) i ++;
                    lineNo ++;
                    bolIdx = i + 1;
                    continue;
                }
                if ((i + 2 <= source.Length) && (source.Substring (i, 2).Equals ("/*"))) {
                    i += 2;
                    while ((i + 1 < source.Length) && (((c = source[i]) != '*') || (source[i+1] != '/'))) {
                        if (c == '\n') {
                            lineNo ++;
                            bolIdx = i + 1;
                        }
                        i ++;
                    }
                    i ++;
                    continue;
                }

                /*
                 * Check for numbers.
                 */
                if ((c >= '0') && (c <= '9')) {
                    int j = TryParseFloat (i);
                    if (j == 0) j = TryParseInt (i);
                    i = -- j;
                    continue;
                }
                if ((c == '.') && (source[i+1] >= '0') && (source[i+1] <= '9')) {
                    int j = TryParseFloat (i);
                    if (j > 0) i = -- j;
                    continue;
                }

                /*
                 * Check for quoted strings.
                 */
                if (c == '"') {
                    StringBuilder sb = new StringBuilder ();
                    bool backslash;
                    int j;

                    backslash = false;
                    for (j = i; ++ j < source.Length;) {
                        c = source[j];
                        if (c == '\\' && !backslash) {
                            backslash = true;
                            continue;
                        }
                        if (c == '\n') {
                            lineNo ++;
                            bolIdx = j + 1;
                        } else {
                            if (!backslash && (c == '"')) break;
                            if (backslash && (c == 'n')) c = '\n';
                            if (backslash && (c == 't')) {
                                sb.Append ("   ");
                                c = ' ';
                            }
                        }
                        backslash = false;
                        sb.Append (c);
                    }
                    if (j - i > MAX_STRING_LEN) {
                        TokenError (i, "string too long, max " + MAX_STRING_LEN);
                    } else {
                        AppendToken (new TokenStr (emsg, filNam, lineNo, i - bolIdx, sb.ToString ()));
                    }
                    i = j;
                    continue;
                }

                /*
                 * Check for quoted characters.
                 */
                if (c == '\'') {
                    char cb = (char)0;
                    bool backslash, overflow, underflow;
                    int j;

                    backslash = false;
                    overflow  = false;
                    underflow = true;
                    for (j = i; ++ j < source.Length;) {
                        c = source[j];
                        if (c == '\\' && !backslash) {
                            backslash = true;
                            continue;
                        }
                        if (c == '\n') {
                            lineNo ++;
                            bolIdx = j + 1;
                        } else {
                            if (!backslash && (c == '\'')) break;
                            if (backslash && (c == 'n')) c = '\n';
                            if (backslash && (c == 't')) c = '\t';
                        }
                        backslash = false;
                        overflow  = !underflow;
                        underflow = false;
                        cb = c;
                    }
                    if (underflow || overflow) {
                        TokenError (i, "character must be exactly one character");
                    } else {
                        AppendToken (new TokenChar (emsg, filNam, lineNo, i - bolIdx, cb));
                    }
                    i = j;
                    continue;
                }

                /*
                 * Check for keywords/names.
                 */
                if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '_') || (c == '$' && options.dollarsigns)) {
                    int j;

                    for (j = i; ++ j < source.Length;) {
                        c = source[j];
                        if (c >= 'a' && c <= 'z') continue;
                        if (c >= 'A' && c <= 'Z') continue;
                        if (c >= '0' && c <= '9') continue;
                        if (c == '$' && options.dollarsigns) continue;
                        if (c != '_') break;
                    }
                    if (j - i > MAX_NAME_LEN) {
                        TokenError (i, "name too long, max " + MAX_NAME_LEN);
                    } else {
                        string name = source.Substring (i, j - i);
                        if (name == "quaternion") name = "rotation";  // see lslangtest1.lsl
                        if (keywords.ContainsKey (name)) {
                            Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
                            AppendToken ((Token)keywords[name].Invoke (args));
                        } else if (options.arrays && arrayKeywords.ContainsKey (name)) {
                            Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
                            AppendToken ((Token)arrayKeywords[name].Invoke (args));
                        } else if (options.advFlowCtl && advFlowCtlKeywords.ContainsKey (name)) {
                            Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
                            AppendToken ((Token)advFlowCtlKeywords[name].Invoke (args));
                        } else if (options.tryCatch && tryCatchKeywords.ContainsKey (name)) {
                            Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
                            AppendToken ((Token)tryCatchKeywords[name].Invoke (args));
                        } else if (options.objects && objectsKeywords.ContainsKey (name)) {
                            Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
                            AppendToken ((Token)objectsKeywords[name].Invoke (args));
                        } else if (options.chars && charsKeywords.ContainsKey (name)) {
                            Object[] args = new Object[] { emsg, filNam, lineNo, i - bolIdx };
                            AppendToken ((Token)charsKeywords[name].Invoke (args));
                        } else {
                            AppendToken (new TokenName (emsg, filNam, lineNo, i - bolIdx, name));
                        }
                    }
                    i = -- j;
                    continue;
                }

                /*
                 * Check for option enables.
                 */
                if ((c == ';') && (lastToken is TokenName) && 
                    (lastToken.prevToken is TokenName) && 
                    (strcasecmp(((TokenName)lastToken.prevToken).val, "xmroption") == 0)) {
                    string opt = ((TokenName)lastToken).val;
                    if (strcasecmp (opt, "arrays") == 0) {
                        options.arrays = true;
                    } else if (strcasecmp (opt, "advflowctl") == 0) {
                        options.advFlowCtl = true;
                    } else if (strcasecmp (opt, "trycatch") == 0) {
                        options.tryCatch = true;
                    } else if (strcasecmp (opt, "objects") == 0) {
                        options.objects = true;
                    } else if (strcasecmp (opt, "chars") == 0) {
                        options.chars = true;
                    } else if (strcasecmp (opt, "norighttoleft") == 0) {
                        options.noRightToLeft = true;
                    } else if (strcasecmp (opt, "dollarsigns") == 0) {
                        options.dollarsigns = true;
                    } else {
                        lastToken.ErrorMsg ("unknown XMROption");
                    }
                    lastToken = lastToken.prevToken.prevToken;
                    lastToken.nextToken = null;
                    continue;
                }

                /*
                 * Handle 'xmroption' 'expirydays' numberofdays ';'
                 */
                if ((c == ';') && 
                    (lastToken is TokenInt) && 
                    (lastToken.prevToken is TokenName) && 
                    (lastToken.prevToken.prevToken is TokenName) &&
                    (strcasecmp(((TokenName)lastToken.prevToken.prevToken).val, "xmroption") == 0) && 
                    (strcasecmp(((TokenName)lastToken.prevToken).val, "expirydays") == 0)) {
                    expiryDays = ((TokenInt)lastToken).val;
                    this.lastToken = lastToken.prevToken.prevToken.prevToken;
                    this.lastToken.nextToken = null;
                    continue;
                }


                /*
                 * Handle 'xmroption' 'include' sourceurl ';'
                 */
                if ((c == ';') && 
                    (lastToken is TokenStr) && 
                    (lastToken.prevToken is TokenName) && 
                    (lastToken.prevToken.prevToken is TokenName) &&
                    (strcasecmp(((TokenName)lastToken.prevToken.prevToken).val, "xmroption") == 0) && 
                    (strcasecmp(((TokenName)lastToken.prevToken).val, "include") == 0)) {

                    string newURL      = ((TokenStr)lastToken).val;
                    if (newURL == "") {
                        lastToken.ErrorMsg ("empty URL string");
                        continue;
                    }
                    string newCameFrom = CreateURL (this.cameFrom, newURL);
                    string newSource   = ReadSourceFromURL (newCameFrom);

                    this.lastToken     = lastToken.prevToken.prevToken.prevToken;
                    this.lastToken.nextToken = null;

                    if (newSource != null) {
                        if (saveSource != null) {
                            saveSource.WriteLine ("");
                            saveSource.WriteLine ("********************************************************************************");
                            saveSource.WriteLine ("****  include url: " + newCameFrom);
                            saveSource.WriteLine ("********************************************************************************");
                            saveSource.WriteLine (newSource);
                        }

                        string saveSourc    = this.source;
                        string saveFilNam   = this.filNam;
                        string saveCameFrom = this.cameFrom;
                        int saveBolIdx      = this.bolIdx;
                        int saveLineNo      = this.lineNo;
                        Options saveOptions = this.options;
                        this.source   = newSource;
                        this.filNam   = newURL;
                        this.cameFrom = newCameFrom;
                        this.options  = new Options ();
                        this.Tokenize ();
                        this.source   = saveSourc;
                        this.filNam   = saveFilNam;
                        this.cameFrom = saveCameFrom;
                        this.bolIdx   = saveBolIdx;
                        this.lineNo   = saveLineNo;
                        this.options  = saveOptions;
                    }
                    continue;
                }

                /*
                 * Lastly, check for delimeters.
                 */
                {
                    int j;
                    int len = 0;

                    for (j = 0; j < delims.Length; j ++) {
                        len = delims[j].str.Length;
                        if ((i + len <= source.Length) && (source.Substring (i, len).Equals (delims[j].str))) break;
                    }
                    if (j < delims.Length) {
                        Object[] args = { emsg, filNam, lineNo, i - bolIdx };
                        Token kwToken = (Token)delims[j].ctorInfo.Invoke (args);
                        AppendToken (kwToken);
                        i += -- len;
                        continue;
                    }
                }

                /*
                 * Don't know what it is!
                 */
                TokenError (i, "unknown character '" + c + "'");
            }
        }

        private static int strcasecmp (String s, String t)
        {
            return String.Compare(s,t,StringComparison.OrdinalIgnoreCase);
        }

        /**
         * @brief try to parse a floating-point number from the source
         * @param i = starting position within this.source of number
         * @returns 0: not a floating point number, try something else
         *       else: position in this.source of terminating character, ie, past number
         *             TokenFloat appended to token list
         *             or error message has been output
         */
        private int TryParseFloat (int i)
        {
            bool decimals, error, negexp, nulexp;
            char c;
            double f, f10;
            int exponent, j, x, y;
            ulong m, mantissa;

            decimals = false;
            error    = false;
            exponent = 0;
            mantissa = 0;
            for (j = i; j < source.Length; j ++) {
                c = source[j];
                if ((c >= '0') && (c <= '9')) {
                    m = mantissa * 10 + (ulong)(c - '0');
                    if (m / 10 != mantissa) {
                        if (!decimals) exponent ++;
                    } else {
                        mantissa = m;
                        if (decimals) exponent --;
                    }
                    continue;
                }
                if (c == '.') {
                    if (decimals) {
                        TokenError (i, "more than one decimal point");
                        return j;
                    }
                    decimals = true;
                    continue;
                }
                if ((c == 'E') || (c == 'e')) {
                    if (++ j >= source.Length) {
                        TokenError (i, "floating exponent off end of source");
                        return j;
                    }
                    c = source[j];
                    negexp = (c == '-');
                    if (negexp || (c == '+')) j ++;
                    y = 0;
                    nulexp = true;
                    for (; j < source.Length; j ++) {
                        c = source[j];
                        if ((c < '0') || (c > '9')) break;
                        x = y * 10 + (c - '0');
                        if (x / 10 != y) {
                            if (!error) TokenError (i, "floating exponent overflow");
                            error = true;
                        }
                        y = x;
                        nulexp = false;
                    }
                    if (nulexp) {
                        TokenError (i, "bad or missing floating exponent");
                        return j;
                    }
                    if (negexp) {
                        x = exponent - y;
                        if (x > exponent) {
                            if (!error) TokenError (i, "floating exponent overflow");
                            error = true;
                        }
                    } else {
                        x = exponent + y;
                        if (x < exponent) {
                            if (!error) TokenError (i, "floating exponent overflow");
                            error = true;
                        }
                    }
                    exponent = x;
                }
                break;
            }
            if (!decimals) {
                return 0;
            }

            f = mantissa;
            if ((exponent != 0) && (mantissa != 0) && !error) {
                f10 = 10.0;
                if (exponent < 0) {
                    exponent = -exponent;
                    while (exponent > 0) {
                        if ((exponent & 1) != 0) {
                            f /= f10;
                        }
                        exponent /= 2;
                        f10 *= f10;
                    }
                } else {
                    while (exponent > 0) {
                        if ((exponent & 1) != 0) {
                            f *= f10;
                        }
                        exponent /= 2;
                        f10 *= f10;
                    }
                }
            }
            if (!error) {
                AppendToken (new TokenFloat (emsg, filNam, lineNo, i - bolIdx, f));
            }
            return j;
        }

        /**
         * @brief try to parse an integer number from the source
         * @param i = starting position within this.source of number
         * @returns 0: not an integer number, try something else
         *       else: position in this.source of terminating character, ie, past number
         *             TokenInt appended to token list
         *             or error message has been output
         */
        private int TryParseInt (int i)
        {
            bool error;
            char c;
            int j;
            uint basse, m, mantissa;

            basse    = 10;
            error    = false;
            mantissa = 0;
            for (j = i; j < source.Length; j ++) {
                c = source[j];
                if ((c >= '0') && (c <= '9')) {
                    m = mantissa * basse + (uint)(c - '0');
                    if (m / basse != mantissa) {
                        if (!error) TokenError (i, "integer overflow");
                        error = true;
                    }
                    mantissa = m;
                    continue;
                }
                if ((basse == 16) && ((c >= 'A') && (c <= 'F'))) {
                    m = mantissa * basse + (uint)(c - 'A') + 10U;
                    if (m / basse != mantissa) {
                        if (!error) TokenError (i, "integer overflow");
                        error = true;
                    }
                    mantissa = m;
                    continue;
                }
                if ((basse == 16) && ((c >= 'a') && (c <= 'f'))) {
                    m = mantissa * basse + (uint)(c - 'a') + 10U;
                    if (m / basse != mantissa) {
                        if (!error) TokenError (i, "integer overflow");
                        error = true;
                    }
                    mantissa = m;
                    continue;
                }
                if (((c == 'x') || (c == 'X')) && (mantissa == 0) && (basse == 10)) {
                    basse = 16;
                    continue;
                }
                break;
            }
            if (!error) {
                AppendToken (new TokenInt (emsg, filNam, lineNo, i - bolIdx, (int)mantissa));
            }
            return j;
        }

        /**
         * @brief append token on to end of list
         * @param newToken = token to append
         * @returns with token appended onto this.lastToken
         */
        private void AppendToken (Token newToken)
        {
            newToken.nextToken  = null;
            newToken.prevToken  = lastToken;
            newToken.nr2l       = this.options.noRightToLeft;
            lastToken.nextToken = newToken;
            lastToken           = newToken;
        }

        /**
         * @brief print tokenizing error message
         *        and remember that we've an error
         * @param i = position within source file of the error
         * @param message = error message text
         * @returns with this.youveAnError set
         */
        private void TokenError (int i, string message)
        {
            Token temp = new Token (this.emsg, this.filNam, this.lineNo, i - this.bolIdx);
            temp.ErrorMsg (message);
            youveAnError = true;
        }

        /**
         * @brief get a token's constructor
         * @param tokenType = token's type
         * @returns token's constructor
         */
        private static Type[] constrTypes = new Type[] {
            typeof (TokenErrorMessage), typeof (string), typeof (int), typeof (int)
        };

        private static System.Reflection.ConstructorInfo GetTokenCtor (Type tokenType)
        {
            return tokenType.GetConstructor (constrTypes);
        }

        /**
         * @brief delimeter table
         */
        private class Delim {
            public string str;
            public System.Reflection.ConstructorInfo ctorInfo;
            public Delim (string str, Type type)
            {
                this.str = str;
                ctorInfo = GetTokenCtor (type);
            }
        }

        private static Delim[] delims = new Delim[] {
            new Delim ("...", typeof (TokenKwDotDotDot)),
            new Delim ("&&&", typeof (TokenKwAndAndAnd)),
            new Delim ("|||", typeof (TokenKwOrOrOr)),
            new Delim ("<<=", typeof (TokenKwAsnLSh)),
            new Delim (">>=", typeof (TokenKwAsnRSh)),
            new Delim ("<=",  typeof (TokenKwCmpLE)),
            new Delim (">=",  typeof (TokenKwCmpGE)),
            new Delim ("==",  typeof (TokenKwCmpEQ)),
            new Delim ("!=",  typeof (TokenKwCmpNE)),
            new Delim ("++",  typeof (TokenKwIncr)),
            new Delim ("--",  typeof (TokenKwDecr)),
            new Delim ("&&",  typeof (TokenKwAndAnd)),
            new Delim ("||",  typeof (TokenKwOrOr)),
            new Delim ("+=",  typeof (TokenKwAsnAdd)),
            new Delim ("&=",  typeof (TokenKwAsnAnd)),
            new Delim ("-=",  typeof (TokenKwAsnSub)),
            new Delim ("*=",  typeof (TokenKwAsnMul)),
            new Delim ("/=",  typeof (TokenKwAsnDiv)),
            new Delim ("%=",  typeof (TokenKwAsnMod)),
            new Delim ("|=",  typeof (TokenKwAsnOr)),
            new Delim ("^=",  typeof (TokenKwAsnXor)),
            new Delim ("<<",  typeof (TokenKwLSh)),
            new Delim (">>",  typeof (TokenKwRSh)),
            new Delim ("~",   typeof (TokenKwTilde)),
            new Delim ("!",   typeof (TokenKwExclam)),
            new Delim ("@",   typeof (TokenKwAt)),
            new Delim ("%",   typeof (TokenKwMod)),
            new Delim ("^",   typeof (TokenKwXor)),
            new Delim ("&",   typeof (TokenKwAnd)),
            new Delim ("*",   typeof (TokenKwMul)),
            new Delim ("(",   typeof (TokenKwParOpen)),
            new Delim (")",   typeof (TokenKwParClose)),
            new Delim ("-",   typeof (TokenKwSub)),
            new Delim ("+",   typeof (TokenKwAdd)),
            new Delim ("=",   typeof (TokenKwAssign)),
            new Delim ("{",   typeof (TokenKwBrcOpen)),
            new Delim ("}",   typeof (TokenKwBrcClose)),
            new Delim ("[",   typeof (TokenKwBrkOpen)),
            new Delim ("]",   typeof (TokenKwBrkClose)),
            new Delim (";",   typeof (TokenKwSemi)),
            new Delim (":",   typeof (TokenKwColon)),
            new Delim ("<",   typeof (TokenKwCmpLT)),
            new Delim (">",   typeof (TokenKwCmpGT)),
            new Delim (",",   typeof (TokenKwComma)),
            new Delim (".",   typeof (TokenKwDot)),
            new Delim ("?",   typeof (TokenKwQMark)),
            new Delim ("/",   typeof (TokenKwDiv)),
            new Delim ("|",   typeof (TokenKwOr)),
            new Delim ("#",   typeof (TokenKwHash))
        };

        /**
         * @brief keyword tables
         *        The keyword tables translate a keyword string
         *        to the corresponding token constructor.
         */
        private static Dictionary<string, System.Reflection.ConstructorInfo> keywords           = BuildKeywords ();
        private static Dictionary<string, System.Reflection.ConstructorInfo> arrayKeywords      = BuildArrayKeywords ();
        private static Dictionary<string, System.Reflection.ConstructorInfo> advFlowCtlKeywords = BuildAdvFlowCtlKeywords ();
        private static Dictionary<string, System.Reflection.ConstructorInfo> tryCatchKeywords   = BuildTryCatchKeywords ();
        private static Dictionary<string, System.Reflection.ConstructorInfo> objectsKeywords    = BuildObjectsKeywords ();
        private static Dictionary<string, System.Reflection.ConstructorInfo> charsKeywords      = BuildCharsKeywords ();

        private static Dictionary<string, System.Reflection.ConstructorInfo> BuildKeywords ()
        {
            Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo> ();

            kws.Add ("default",  GetTokenCtor (typeof (TokenKwDefault)));
            kws.Add ("do",       GetTokenCtor (typeof (TokenKwDo)));
            kws.Add ("else",     GetTokenCtor (typeof (TokenKwElse)));
            kws.Add ("float",    GetTokenCtor (typeof (TokenTypeFloat)));
            kws.Add ("for",      GetTokenCtor (typeof (TokenKwFor)));
            kws.Add ("if",       GetTokenCtor (typeof (TokenKwIf)));
            kws.Add ("integer",  GetTokenCtor (typeof (TokenTypeInt)));
            kws.Add ("list",     GetTokenCtor (typeof (TokenTypeList)));
            kws.Add ("jump",     GetTokenCtor (typeof (TokenKwJump)));
            kws.Add ("key",      GetTokenCtor (typeof (TokenTypeKey)));
            kws.Add ("return",   GetTokenCtor (typeof (TokenKwRet)));
            kws.Add ("rotation", GetTokenCtor (typeof (TokenTypeRot)));
            kws.Add ("state",    GetTokenCtor (typeof (TokenKwState)));
            kws.Add ("string",   GetTokenCtor (typeof (TokenTypeStr)));
            kws.Add ("vector",   GetTokenCtor (typeof (TokenTypeVec)));
            kws.Add ("while",    GetTokenCtor (typeof (TokenKwWhile)));

            return kws;
        }

        private static Dictionary<string, System.Reflection.ConstructorInfo> BuildArrayKeywords ()
        {
            Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo> ();

            kws.Add ("array",   GetTokenCtor (typeof (TokenTypeArray)));
            kws.Add ("foreach", GetTokenCtor (typeof (TokenKwForEach)));
            kws.Add ("in",      GetTokenCtor (typeof (TokenKwIn)));
            kws.Add ("is",      GetTokenCtor (typeof (TokenKwIs)));
            kws.Add ("object",  GetTokenCtor (typeof (TokenTypeObject)));
            kws.Add ("undef",   GetTokenCtor (typeof (TokenKwUndef)));

            return kws;
        }

        private static Dictionary<string, System.Reflection.ConstructorInfo> BuildAdvFlowCtlKeywords ()
        {
            Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo> ();

            kws.Add ("break",    GetTokenCtor (typeof (TokenKwBreak)));
            kws.Add ("case",     GetTokenCtor (typeof (TokenKwCase)));
            kws.Add ("constant", GetTokenCtor (typeof (TokenKwConst)));
            kws.Add ("continue", GetTokenCtor (typeof (TokenKwCont)));
            kws.Add ("switch",   GetTokenCtor (typeof (TokenKwSwitch)));

            return kws;
        }

        private static Dictionary<string, System.Reflection.ConstructorInfo> BuildTryCatchKeywords ()
        {
            Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo> ();

            kws.Add ("catch",     GetTokenCtor (typeof (TokenKwCatch)));
            kws.Add ("exception", GetTokenCtor (typeof (TokenTypeExc)));
            kws.Add ("finally",   GetTokenCtor (typeof (TokenKwFinally)));
            kws.Add ("throw",     GetTokenCtor (typeof (TokenKwThrow)));
            kws.Add ("try",       GetTokenCtor (typeof (TokenKwTry)));

            return kws;
        }

        private static Dictionary<string, System.Reflection.ConstructorInfo> BuildObjectsKeywords ()
        {
            Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo> ();

            kws.Add ("abstract",    GetTokenCtor (typeof (TokenKwAbstract)));
            kws.Add ("base",        GetTokenCtor (typeof (TokenKwBase)));
            kws.Add ("class",       GetTokenCtor (typeof (TokenKwClass)));
            kws.Add ("constructor", GetTokenCtor (typeof (TokenKwConstructor)));
            kws.Add ("delegate",    GetTokenCtor (typeof (TokenKwDelegate)));
            kws.Add ("destructor",  GetTokenCtor (typeof (TokenKwDestructor)));
            kws.Add ("final",       GetTokenCtor (typeof (TokenKwFinal)));
            kws.Add ("get",         GetTokenCtor (typeof (TokenKwGet)));
            kws.Add ("interface",   GetTokenCtor (typeof (TokenKwInterface)));
            kws.Add ("new",         GetTokenCtor (typeof (TokenKwNew)));
            kws.Add ("override",    GetTokenCtor (typeof (TokenKwOverride)));
            kws.Add ("partial",     GetTokenCtor (typeof (TokenKwPartial)));
            kws.Add ("private",     GetTokenCtor (typeof (TokenKwPrivate)));
            kws.Add ("protected",   GetTokenCtor (typeof (TokenKwProtected)));
            kws.Add ("public",      GetTokenCtor (typeof (TokenKwPublic)));
            kws.Add ("set",         GetTokenCtor (typeof (TokenKwSet)));
            kws.Add ("static",      GetTokenCtor (typeof (TokenKwStatic)));
            kws.Add ("this",        GetTokenCtor (typeof (TokenKwThis)));
            kws.Add ("typedef",     GetTokenCtor (typeof (TokenKwTypedef)));
            kws.Add ("virtual",     GetTokenCtor (typeof (TokenKwVirtual)));

            return kws;
        }

        private static Dictionary<string, System.Reflection.ConstructorInfo> BuildCharsKeywords ()
        {
            Dictionary<string, System.Reflection.ConstructorInfo> kws = new Dictionary<string, System.Reflection.ConstructorInfo> ();

            kws.Add ("char", GetTokenCtor (typeof (TokenTypeChar)));

            return kws;
        }

        /**
         * @brief Create a URL from a base URL and a relative string
         * @param oldurl = base url string
         * @param relurl = relative url
         * @returns new url string
         */
        private static string CreateURL (string oldurl, string relurl)
        {
            if (relurl.IndexOf ("://") >= 0) return relurl;
            StringBuilder newurl = new StringBuilder (oldurl.Length + relurl.Length);
            if (relurl[0] == '/') {
                // file:///oldname + /newname => file:///newname
                // http://webserver.com/oldname + /newname => http://webserver.com/newname
                int i = oldurl.IndexOf ("://") + 3;
                int j = oldurl.IndexOf ('/', i);
                if (j < 0) j = oldurl.Length;
                newurl.Append (oldurl.Substring (0, j));
                newurl.Append (relurl);
            } else {
                // file:///oldname + newname => file:///newname
                // http://webserver.com/oldname + newname => http://webserver.com/newname
                int i = oldurl.LastIndexOf ('/') + 1;
                newurl.Append (oldurl.Substring (0, i));
                newurl.Append (relurl);
            }
            return newurl.ToString ();
        }

        /**
         * @brief Read source file from a webserver somewhere out there.
         */
        private const int MAX_INCLUDE_SIZE = 100000;
        private Dictionary<string, string> scriptIncludes = new Dictionary<string, string> ();
        private string ReadSourceFromURL (string url)
        {
            Stream stream = null;
            StreamReader reader = null;

            try {

                /*
                 * Get stream to read from webserver.
                 */
                stream = MMRWebRequest.MakeRequest ("GET", url, null, 0);
                reader = new StreamReader (stream);

                /*
                 * Read file from stream.
                 */
                char[] buf = new char[4000];
                int len = 0;
                int total = 0;
                List<char[]> fullBuffs = new List<char[]> ();
                string signature = null;

                while (true) {

                    /*
                     * Read a big chunk of characters.
                     */
                    len = reader.ReadBlock (buf, 0, buf.Length);

                    /*
                     * Signature is first line of the first chunk read and must be contained therein.
                     * If an include file with the same signature has already been seen by this script, 
                     * this include file is ignored.
                     */
                    if (signature == null) {
                        signature   = new String (buf, 0, len);
                        int siglen  = signature.IndexOf ('\n');
                        if (siglen <= 0) {
                            throw new Exception ("missing signature in first " + len + " characters: " + url);
                        }
                        signature   = signature.Substring (0, siglen);
                        if (scriptIncludes.ContainsKey (signature)) return null;
                        scriptIncludes.Add (signature, "");
                    }

                    /*
                     * Signature is ok, stash full blocks away and keep reading.
                     * If short read, means we have hit the end of the stream.
                     */
                    total += len;
                    if (total > MAX_INCLUDE_SIZE) {
                        throw new Exception ("script include exceeds maximum " + MAX_INCLUDE_SIZE + ": " + url);
                    }
                    if (len < buf.Length) break;
                    fullBuffs.Add (buf);
                    buf = new char[4000];
                }

                /*
                 * Return the whole thing as one string.
                 */
                StringBuilder sb = new StringBuilder (total + url.Length + 20);
                sb.Append ("# 1 \"");
                sb.Append (url);
                sb.Append ("\"\n");
                foreach (char[] fullBuff in fullBuffs) {
                    sb.Append (fullBuff);
                }
                sb.Append (buf, 0, len);
                return sb.ToString ();
            } finally {
                     if (reader   != null) reader.Close ();
                else if (stream   != null) stream.Close ();
            }
        }
    }

    /**
     * @brief All output token types in addition to TokenBegin.
     *        They are all sub-types of Token.
     */

    public class TokenChar : Token {
        public char val;
        public TokenChar (TokenErrorMessage emsg, string file, int line, int posn, char val) : base (emsg, file, line, posn)
        {
            this.val = val;
        }
        public TokenChar (Token original, char val) : base (original)
        {
            this.val = val;
        }
        public override string ToString ()
        {
            switch (val) {
                case '\'': return "'\\''";
                case '\\': return "'\\\\'";
                case '\n': return "'\\n'";
                case '\t': return "'\\t'";
                default:   return "'" + val + "'";
            }
        }
    }

    public class TokenFloat : Token {
        public double val;
        public TokenFloat (TokenErrorMessage emsg, string file, int line, int posn, double val) : base (emsg, file, line, posn)
        {
            this.val = val;
        }
        public override string ToString ()
        {
            return val.ToString ();
        }
    }

    public class TokenInt : Token {
        public int val;
        public TokenInt (TokenErrorMessage emsg, string file, int line, int posn, int val) : base (emsg, file, line, posn)
        {
            this.val = val;
        }
        public TokenInt (Token original, int val) : base (original)
        {
            this.val = val;
        }
        public override string ToString ()
        {
            return val.ToString ();
        }
    }

    public class TokenName : Token {
        public string val;
        public TokenName (TokenErrorMessage emsg, string file, int line, int posn, string val) : base (emsg, file, line, posn)
        {
            this.val = val;
        }
        public TokenName (Token original, string val) : base (original)
        {
            this.val = val;
        }
        public override string ToString ()
        {
            return this.val;
        }
    }

    public class TokenStr : Token {
        public string val;
        public TokenStr (TokenErrorMessage emsg, string file, int line, int posn, string val) : base (emsg, file, line, posn)
        {
            this.val = val;
        }
        public override string ToString ()
        {
            if ((val.IndexOf ('"') < 0) && 
                (val.IndexOf ('\\') < 0) && 
                (val.IndexOf ('\n') < 0) && 
                (val.IndexOf ('\t') < 0)) return "\"" + val + "\"";

            int len = val.Length;
            StringBuilder sb = new StringBuilder (len * 2 + 2);
            sb.Append ('"');
            for (int i = 0; i < len; i ++) {
                char c = val[i];
                switch (c) {
                    case '"': {
                        sb.Append ('\\');
                        sb.Append ('"');
                        break;
                    }
                    case '\\': {
                        sb.Append ('\\');
                        sb.Append ('\\');
                        break;
                    }
                    case '\n': {
                        sb.Append ('\\');
                        sb.Append ('n');
                        break;
                    }
                    case '\t': {
                        sb.Append ('\\');
                        sb.Append ('t');
                        break;
                    }
                    default: {
                        sb.Append (c);
                        break;
                    }
                }
            }
            return sb.ToString ();
        }
    }

    /*
     * This one marks the end-of-file.
     */
    public class TokenEnd : Token { public TokenEnd (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { } }

    /*
     * Various keywords and delimeters.
     */
    public delegate object TokenRValConstBinOpDelegate (object left, object right);
    public delegate object TokenRValConstUnOpDelegate  (object right);

    public class TokenKw : Token {
        public TokenRValConstBinOpDelegate binOpConst;
        public TokenRValConstUnOpDelegate  unOpConst;
        public bool sdtClassOp;
        public TokenKw (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenKw (Token original) : base (original)  { }
    }

    public class TokenKwDotDotDot : TokenKw { public TokenKwDotDotDot (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwDotDotDot (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "..."; } }
    public class TokenKwAndAndAnd : TokenKw { public TokenKwAndAndAnd (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwAndAndAnd (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "&&&"; } }
    public class TokenKwOrOrOr : TokenKw { public TokenKwOrOrOr (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwOrOrOr (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "|||"; } }
    public class TokenKwAsnLSh : TokenKw { public TokenKwAsnLSh (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnLSh (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "<<="; } }
    public class TokenKwAsnRSh : TokenKw { public TokenKwAsnRSh (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnRSh (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return ">>="; } }
    public class TokenKwCmpLE : TokenKw { public TokenKwCmpLE (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwCmpLE (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "<="; } }
    public class TokenKwCmpGE : TokenKw { public TokenKwCmpGE (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwCmpGE (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return ">="; } }
    public class TokenKwCmpEQ : TokenKw { public TokenKwCmpEQ (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwCmpEQ (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "=="; } }
    public class TokenKwCmpNE : TokenKw { public TokenKwCmpNE (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwCmpNE (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "!="; } }
    public class TokenKwIncr : TokenKw { public TokenKwIncr (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwIncr (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "++"; } }
    public class TokenKwDecr : TokenKw { public TokenKwDecr (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwDecr (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "--"; } }
    public class TokenKwAndAnd : TokenKw { public TokenKwAndAnd (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAndAnd (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "&&"; } }
    public class TokenKwOrOr : TokenKw { public TokenKwOrOr (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwOrOr (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "||"; } }
    public class TokenKwAsnAdd : TokenKw { public TokenKwAsnAdd (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnAdd (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "+="; } }
    public class TokenKwAsnAnd : TokenKw { public TokenKwAsnAnd (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnAnd (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "&="; } }
    public class TokenKwAsnSub : TokenKw { public TokenKwAsnSub (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnSub (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "-="; } }
    public class TokenKwAsnMul : TokenKw { public TokenKwAsnMul (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnMul (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "*="; } }
    public class TokenKwAsnDiv : TokenKw { public TokenKwAsnDiv (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnDiv (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "/="; } }
    public class TokenKwAsnMod : TokenKw { public TokenKwAsnMod (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnMod (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "%="; } }
    public class TokenKwAsnOr : TokenKw { public TokenKwAsnOr (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnOr (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "|="; } }
    public class TokenKwAsnXor : TokenKw { public TokenKwAsnXor (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAsnXor (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "^="; } }
    public class TokenKwLSh : TokenKw { public TokenKwLSh (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.LSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwLSh (Token original) : base (original) { binOpConst = TokenRValConstOps.LSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "<<"; } }
    public class TokenKwRSh : TokenKw { public TokenKwRSh (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.RSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwRSh (Token original) : base (original) { binOpConst = TokenRValConstOps.RSh; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return ">>"; } }
    public class TokenKwTilde : TokenKw { public TokenKwTilde (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Not; sdtClassOp = true; } public TokenKwTilde (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Not; sdtClassOp = true; } public override string ToString () { return "~"; } }
    public class TokenKwExclam : TokenKw { public TokenKwExclam (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwExclam (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "!"; } }
    public class TokenKwAt : TokenKw { public TokenKwAt (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwAt (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "@"; } }
    public class TokenKwMod : TokenKw { public TokenKwMod (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Mod; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwMod (Token original) : base (original) { binOpConst = TokenRValConstOps.Mod; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "%"; } }
    public class TokenKwXor : TokenKw { public TokenKwXor (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Xor; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwXor (Token original) : base (original) { binOpConst = TokenRValConstOps.Xor; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "^"; } }
    public class TokenKwAnd : TokenKw { public TokenKwAnd (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.And; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAnd (Token original) : base (original) { binOpConst = TokenRValConstOps.And; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "&"; } }
    public class TokenKwMul : TokenKw { public TokenKwMul (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Mul; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwMul (Token original) : base (original) { binOpConst = TokenRValConstOps.Mul; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "*"; } }
    public class TokenKwParOpen : TokenKw { public TokenKwParOpen (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwParOpen (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "("; } }
    public class TokenKwParClose : TokenKw { public TokenKwParClose (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwParClose (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return ")"; } }
    public class TokenKwSub : TokenKw { public TokenKwSub (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Sub; unOpConst = TokenRValConstOps.Neg; sdtClassOp = true; } public TokenKwSub (Token original) : base (original) { binOpConst = TokenRValConstOps.Sub; unOpConst = TokenRValConstOps.Neg; sdtClassOp = true; } public override string ToString () { return "-"; } }
    public class TokenKwAdd : TokenKw { public TokenKwAdd (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Add; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwAdd (Token original) : base (original) { binOpConst = TokenRValConstOps.Add; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "+"; } }
    public class TokenKwAssign : TokenKw { public TokenKwAssign (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwAssign (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "="; } }
    public class TokenKwBrcOpen : TokenKw { public TokenKwBrcOpen (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwBrcOpen (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "{"; } }
    public class TokenKwBrcClose : TokenKw { public TokenKwBrcClose (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwBrcClose (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "}"; } }
    public class TokenKwBrkOpen : TokenKw { public TokenKwBrkOpen (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwBrkOpen (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "["; } }
    public class TokenKwBrkClose : TokenKw { public TokenKwBrkClose (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwBrkClose (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "]"; } }
    public class TokenKwSemi : TokenKw { public TokenKwSemi (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwSemi (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return ";"; } }
    public class TokenKwColon : TokenKw { public TokenKwColon (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwColon (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return ":"; } }
    public class TokenKwCmpLT : TokenKw { public TokenKwCmpLT (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwCmpLT (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "<"; } }
    public class TokenKwCmpGT : TokenKw { public TokenKwCmpGT (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwCmpGT (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return ">"; } }
    public class TokenKwComma : TokenKw { public TokenKwComma (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwComma (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return ","; } }
    public class TokenKwDot : TokenKw { public TokenKwDot (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwDot (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "."; } }
    public class TokenKwQMark : TokenKw { public TokenKwQMark (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwQMark (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "?"; } }
    public class TokenKwDiv : TokenKw { public TokenKwDiv (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Div; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwDiv (Token original) : base (original) { binOpConst = TokenRValConstOps.Div; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "/"; } }
    public class TokenKwOr : TokenKw { public TokenKwOr (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Or; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public TokenKwOr (Token original) : base (original) { binOpConst = TokenRValConstOps.Or; unOpConst = TokenRValConstOps.Null; sdtClassOp = true; } public override string ToString () { return "|"; } }
    public class TokenKwHash : TokenKw { public TokenKwHash (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwHash (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "#"; } }

    public class TokenKwAbstract : TokenKw { public TokenKwAbstract (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwAbstract (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "abstract"; } }
    public class TokenKwBase : TokenKw { public TokenKwBase (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwBase (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "base"; } }
    public class TokenKwBreak : TokenKw { public TokenKwBreak (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwBreak (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "break"; } }
    public class TokenKwCase : TokenKw { public TokenKwCase (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwCase (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "case"; } }
    public class TokenKwCatch : TokenKw { public TokenKwCatch (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwCatch (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "catch"; } }
    public class TokenKwClass : TokenKw { public TokenKwClass (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwClass (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "class"; } }
    public class TokenKwConst : TokenKw { public TokenKwConst (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwConst (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "constant"; } }
    public class TokenKwConstructor : TokenKw { public TokenKwConstructor (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwConstructor (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "constructor"; } }
    public class TokenKwCont : TokenKw { public TokenKwCont (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwCont (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "continue"; } }
    public class TokenKwDelegate : TokenKw { public TokenKwDelegate (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwDelegate (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "delegate"; } }
    public class TokenKwDefault : TokenKw { public TokenKwDefault (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwDefault (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "default"; } }
    public class TokenKwDestructor : TokenKw { public TokenKwDestructor (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwDestructor (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "destructor"; } }
    public class TokenKwDo : TokenKw { public TokenKwDo (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwDo (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "do"; } }
    public class TokenKwElse : TokenKw { public TokenKwElse (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwElse (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "else"; } }
    public class TokenKwFinal : TokenKw { public TokenKwFinal (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwFinal (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "final"; } }
    public class TokenKwFinally : TokenKw { public TokenKwFinally (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwFinally (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "finally"; } }
    public class TokenKwFor : TokenKw { public TokenKwFor (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwFor (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "for"; } }
    public class TokenKwForEach : TokenKw { public TokenKwForEach (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwForEach (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "foreach"; } }
    public class TokenKwGet : TokenKw { public TokenKwGet (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwGet (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "get"; } }
    public class TokenKwIf : TokenKw { public TokenKwIf (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwIf (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "if"; } }
    public class TokenKwIn : TokenKw { public TokenKwIn (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwIn (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "in"; } }
    public class TokenKwInterface : TokenKw { public TokenKwInterface (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwInterface (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "interface"; } }
    public class TokenKwIs : TokenKw { public TokenKwIs (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwIs (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "is"; } }
    public class TokenKwJump : TokenKw { public TokenKwJump (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwJump (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "jump"; } }
    public class TokenKwNew : TokenKw { public TokenKwNew (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwNew (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "new"; } }
    public class TokenKwOverride : TokenKw { public TokenKwOverride (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwOverride (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "override"; } }
    public class TokenKwPartial : TokenKw { public TokenKwPartial (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwPartial (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "partial"; } }
    public class TokenKwPrivate : TokenKw { public TokenKwPrivate (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwPrivate (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "private"; } }
    public class TokenKwProtected : TokenKw { public TokenKwProtected (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwProtected (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "protected"; } }
    public class TokenKwPublic : TokenKw { public TokenKwPublic (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwPublic (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "public"; } }
    public class TokenKwRet : TokenKw { public TokenKwRet (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwRet (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "return"; } }
    public class TokenKwSet : TokenKw { public TokenKwSet (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwSet (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "set"; } }
    public class TokenKwState : TokenKw { public TokenKwState (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwState (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "state"; } }
    public class TokenKwStatic : TokenKw { public TokenKwStatic (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwStatic (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "static"; } }
    public class TokenKwSwitch : TokenKw { public TokenKwSwitch (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwSwitch (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "switch"; } }
    public class TokenKwThis : TokenKw { public TokenKwThis (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwThis (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "this"; } }
    public class TokenKwThrow : TokenKw { public TokenKwThrow (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwThrow (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "throw"; } }
    public class TokenKwTry : TokenKw { public TokenKwTry (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwTry (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "try"; } }
    public class TokenKwTypedef : TokenKw { public TokenKwTypedef (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwTypedef (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "typedef"; } }
    public class TokenKwUndef : TokenKw { public TokenKwUndef (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwUndef (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "undef"; } }
    public class TokenKwVirtual : TokenKw { public TokenKwVirtual (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwVirtual (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "virtual"; } }
    public class TokenKwWhile : TokenKw { public TokenKwWhile (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public TokenKwWhile (Token original) : base (original) { binOpConst = TokenRValConstOps.Null; unOpConst = TokenRValConstOps.Null; sdtClassOp = false; } public override string ToString () { return "while"; } }

    /**
     * @brief These static functions attempt to perform arithmetic on two constant
     *        operands to generate the resultant constant.
     *        Likewise for unary operators.
     *
     * @param left  = left-hand value
     * @param right = right-hand value
     * @returns null: not able to perform computation
     *          else: resultant value object
     *
     * Note: it is ok for these to throw any exception (such as overflow or div-by-zero), 
     *       and it will be treated as the 'not able to perform computation' case.
     */
    public class TokenRValConstOps {
        public static object Null (object left, object right) { return null; }
        public static object Div (object left, object right) { if ((left is int) && (right is int)) { return (int)left / (int)right; } if ((left is int) && (right is double)) { return (int)left / (double)right; } if ((left is double) && (right is int)) { return (double)left / (int)right; } if ((left is double) && (right is double)) { return (double)left / (double)right; } return null; }
        public static object Mod (object left, object right) { if ((left is int) && (right is int)) { return (int)left % (int)right; } if ((left is int) && (right is double)) { return (int)left % (double)right; } if ((left is double) && (right is int)) { return (double)left % (int)right; } if ((left is double) && (right is double)) { return (double)left % (double)right; } return null; }
        public static object Mul (object left, object right) { if ((left is int) && (right is int)) { return (int)left * (int)right; } if ((left is int) && (right is double)) { return (int)left * (double)right; } if ((left is double) && (right is int)) { return (double)left * (int)right; } if ((left is double) && (right is double)) { return (double)left * (double)right; } return null; }
        public static object And (object left, object right) { if ((left is int) && (right is int)) { return (int)left & (int)right; } if ((left is int) && (right is double)) { return (int)left & (int)(double)right; } if ((left is double) && (right is int)) { return (int)(double)left & (int)right; } if ((left is double) && (right is double)) { return (int)(double)left & (int)(double)right; } return null; }
        public static object LSh (object left, object right) { if ((left is int) && (right is int)) { return (int)left << (int)right; } if ((left is int) && (right is double)) { return (int)left << (int)(double)right; } if ((left is double) && (right is int)) { return (int)(double)left << (int)right; } if ((left is double) && (right is double)) { return (int)(double)left << (int)(double)right; } return null; }
        public static object Or (object left, object right) { if ((left is int) && (right is int)) { return (int)left | (int)right; } if ((left is int) && (right is double)) { return (int)left | (int)(double)right; } if ((left is double) && (right is int)) { return (int)(double)left | (int)right; } if ((left is double) && (right is double)) { return (int)(double)left | (int)(double)right; } return null; }
        public static object RSh (object left, object right) { if ((left is int) && (right is int)) { return (int)left >> (int)right; } if ((left is int) && (right is double)) { return (int)left >> (int)(double)right; } if ((left is double) && (right is int)) { return (int)(double)left >> (int)right; } if ((left is double) && (right is double)) { return (int)(double)left >> (int)(double)right; } return null; }
        public static object Xor (object left, object right) { if ((left is int) && (right is int)) { return (int)left ^ (int)right; } if ((left is int) && (right is double)) { return (int)left ^ (int)(double)right; } if ((left is double) && (right is int)) { return (int)(double)left ^ (int)right; } if ((left is double) && (right is double)) { return (int)(double)left ^ (int)(double)right; } return null; }
        public static object Add (object left, object right) { if ((left is char) && (right is int)) { return (char)((char)left + (int)right); } if ((left is double) && (right is double)) { return (double)left + (double)right; } if ((left is double) && (right is int)) { return (double)left + (int)right; } if ((left is double) && (right is string)) { return TypeCast.FloatToString((double)left) + (string)right; } if ((left is int) && (right is double)) { return (int)left + (double)right; } if ((left is int) && (right is int)) { return (int)left + (int)right; } if ((left is int) && (right is string)) { return TypeCast.IntegerToString((int)left) + (string)right; } if ((left is string) && (right is char)) { return (string)left + (char)right; } if ((left is string) && (right is double)) { return (string)left + TypeCast.FloatToString((double)right); } if ((left is string) && (right is int)) { return (string)left + TypeCast.IntegerToString ((int)right); } if ((left is string) && (right is string)) { return (string)left + (string)right; } return null; }
        public static object Sub (object left, object right) { if ((left is char) && (right is int)) { return (char)((char)left - (int)right); } if ((left is int) && (right is int)) { return (int)left - (int)right; } if ((left is int) && (right is double)) { return (int)left - (double)right; } if ((left is double) && (right is int)) { return (double)left - (int)right; } if ((left is double) && (right is double)) { return (double)left - (double)right; } return null; }
        public static object Null (object right) { return null; }
        public static object Neg (object right) { if (right is int) { return - (int)right; } if (right is double) { return - (double)right; } return null; }
        public static object Not (object right) { if (right is int) { return ~ (int)right; } return null; }
    }

    /*
     * Various datatypes.
     */
    public abstract class TokenType : Token {

        public TokenType (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenType (Token original) : base (original) { }

        public static TokenType FromSysType (Token original, System.Type typ)
        {
            if (typ == typeof (LSL_List))     return new TokenTypeList      (original);
            if (typ == typeof (LSL_Rotation)) return new TokenTypeRot       (original);
            if (typ == typeof (void))         return new TokenTypeVoid      (original);
            if (typ == typeof (LSL_Vector))   return new TokenTypeVec       (original);
            if (typ == typeof (float))        return new TokenTypeFloat     (original);
            if (typ == typeof (int))          return new TokenTypeInt       (original);
            if (typ == typeof (string))       return new TokenTypeStr       (original);
            if (typ == typeof (double))       return new TokenTypeFloat     (original);
            if (typ == typeof (bool))         return new TokenTypeBool      (original);
            if (typ == typeof (object))       return new TokenTypeObject    (original);
            if (typ == typeof (XMR_Array))    return new TokenTypeArray     (original);
            if (typ == typeof (LSL_Integer))  return new TokenTypeLSLInt    (original);
            if (typ == typeof (LSL_Float))    return new TokenTypeLSLFloat  (original);
            if (typ == typeof (LSL_String))   return new TokenTypeLSLString (original);
            if (typ == typeof (char))         return new TokenTypeChar      (original);
            if (typ == typeof (Exception))    return new TokenTypeExc       (original);

            throw new Exception ("unknown script type " + typ.ToString ());
        }

        public static TokenType FromLSLType (Token original, string typ)
        {
            if (typ == "list")      return new TokenTypeList   (original);
            if (typ == "rotation")  return new TokenTypeRot    (original);
            if (typ == "vector")    return new TokenTypeVec    (original);
            if (typ == "float")     return new TokenTypeFloat  (original);
            if (typ == "integer")   return new TokenTypeInt    (original);
            if (typ == "key")       return new TokenTypeKey    (original);
            if (typ == "string")    return new TokenTypeStr    (original);
            if (typ == "object")    return new TokenTypeObject (original);
            if (typ == "array")     return new TokenTypeArray  (original);
            if (typ == "bool")      return new TokenTypeBool   (original);
            if (typ == "void")      return new TokenTypeVoid   (original);
            if (typ == "char")      return new TokenTypeChar   (original);
            if (typ == "exception") return new TokenTypeExc    (original);

            throw new Exception ("unknown type " + typ);
        }

        /**
         * @brief Estimate the number of bytes of memory taken by one of these
         *        objects.  For objects with widely varying size, return the
         *        smallest it can be.
         */
        public static int StaticSize (System.Type typ)
        {
            if (typ == typeof (LSL_List))     return  96;
            if (typ == typeof (LSL_Rotation)) return  80;
            if (typ == typeof (void))         return   0;
            if (typ == typeof (LSL_Vector))   return  72;
            if (typ == typeof (float))        return   8;
            if (typ == typeof (int))          return   8;
            if (typ == typeof (string))       return  40;
            if (typ == typeof (double))       return   8;
            if (typ == typeof (bool))         return   8;
            if (typ == typeof (XMR_Array))    return  96;
            if (typ == typeof (object))       return  32;
            if (typ == typeof (char))         return   2;

            if (typ == typeof (LSL_Integer))  return  32;
            if (typ == typeof (LSL_Float))    return  32;
            if (typ == typeof (LSL_String))   return  40;

            throw new Exception ("unknown type " + typ.ToString ());
        }

        /**
         * @brief Return the corresponding system type.
         */
        public abstract Type ToSysType ();

        /**
         * @brief Return the equivalent LSL wrapping type.
         *
         *  null: normal
         *  else: LSL-style wrapping, ie, LSL_Integer, LSL_Float, LSL_String
         *        ToSysType()=System.Int32;  lslWrapping=LSL_Integer
         *        ToSysType()=System.Float;  lslWrapping=LSL_Float
         *        ToSysType()=System.String; lslWrapping=LSL_String
         */
        public virtual Type ToLSLWrapType ()
        {
            return null;
        }

        /**
         * @brief Assign slots in either the global variable arrays or the script-defined type instance arrays.
         *        These only need to be implemented for script-visible types, ie, those that a script writer 
         *        can actually define a variable as.
         */
        public virtual void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            throw new Exception ("not implemented for " + ToString () + " (" + GetType () + ")");
        }

        /**
         * @brief Get heap tracking type.
         */
        public virtual Type ToHeapTrackerType ()
        {
            return null;
        }
        public virtual ConstructorInfo GetHeapTrackerCtor ()
        {
            return null;
        }
        public virtual MethodInfo GetHeapTrackerPopMeth ()
        {
            return null;
        }
        public virtual MethodInfo GetHeapTrackerPushMeth ()
        {
            return null;
        }
    }

    public class TokenTypeArray : TokenType {
        private static readonly FieldInfo iarArraysFieldInfo = typeof (XMRInstArrays).GetField ("iarArrays");

        public TokenTypeArray (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeArray (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (XMR_Array); }
        public override string ToString () { return "array"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarArraysFieldInfo;
            declVar.vTableIndex = arSizes.iasArrays ++;
        }
    }
    public class TokenTypeBool : TokenType {
        public TokenTypeBool (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeBool (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (bool); }
        public override string ToString () { return "bool"; }
    }
    public class TokenTypeChar : TokenType {
        private static readonly FieldInfo iarCharsFieldInfo = typeof (XMRInstArrays).GetField ("iarChars");

        public TokenTypeChar (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeChar (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (char); }
        public override string ToString () { return "char"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarCharsFieldInfo;
            declVar.vTableIndex = arSizes.iasChars ++;
        }
    }
    public class TokenTypeExc : TokenType {
        private static readonly FieldInfo iarObjectsFieldInfo = typeof (XMRInstArrays).GetField ("iarObjects");

        public TokenTypeExc (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeExc (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (Exception); }
        public override string ToString () { return "exception"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarObjectsFieldInfo;
            declVar.vTableIndex = arSizes.iasObjects ++;
        }
    }
    public class TokenTypeFloat : TokenType {
        private static readonly FieldInfo iarFloatsFieldInfo = typeof (XMRInstArrays).GetField ("iarFloats");

        public TokenTypeFloat (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeFloat (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (double); }
        public override string ToString () { return "float"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarFloatsFieldInfo;
            declVar.vTableIndex = arSizes.iasFloats ++;
        }
    }
    public class TokenTypeInt : TokenType {
        private static readonly FieldInfo iarIntegersFieldInfo = typeof (XMRInstArrays).GetField ("iarIntegers");

        public TokenTypeInt (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeInt (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (int); }
        public override string ToString () { return "integer"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarIntegersFieldInfo;
            declVar.vTableIndex = arSizes.iasIntegers ++;
        }
    }
    public class TokenTypeKey : TokenType {
        private static readonly FieldInfo iarStringsFieldInfo = typeof (XMRInstArrays).GetField ("iarStrings");

        public TokenTypeKey (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeKey (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (string); }
        public override string ToString () { return "key"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarStringsFieldInfo;
            declVar.vTableIndex = arSizes.iasStrings ++;
        }
    }
    public class TokenTypeList : TokenType {
        private static readonly FieldInfo iarListsFieldInfo = typeof (XMRInstArrays).GetField ("iarLists");
        private static readonly ConstructorInfo htListCtor  = typeof (HeapTrackerList).GetConstructor (new Type [] { typeof (XMRInstAbstract) });
        private static readonly MethodInfo htListPopMeth    = typeof (HeapTrackerList).GetMethod ("Pop", new Type[] { typeof (LSL_List) });
        private static readonly MethodInfo htListPushMeth   = typeof (HeapTrackerList).GetMethod ("Push", new Type[0]);

        public TokenTypeList (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeList (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (LSL_List); }
        public override string ToString () { return "list"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarListsFieldInfo;
            declVar.vTableIndex = arSizes.iasLists ++;
        }
        public override Type ToHeapTrackerType () { return typeof (HeapTrackerList); }
        public override ConstructorInfo GetHeapTrackerCtor () { return htListCtor; }
        public override MethodInfo GetHeapTrackerPopMeth ()   { return htListPopMeth; }
        public override MethodInfo GetHeapTrackerPushMeth ()  { return htListPushMeth; }
    }
    public class TokenTypeObject : TokenType {
        private static readonly FieldInfo iarObjectsFieldInfo = typeof (XMRInstArrays).GetField ("iarObjects");
        private static readonly ConstructorInfo htObjectCtor  = typeof (HeapTrackerObject).GetConstructor (new Type [] { typeof (XMRInstAbstract) });
        private static readonly MethodInfo htObjectPopMeth    = typeof (HeapTrackerObject).GetMethod ("Pop", new Type[] { typeof (object) });
        private static readonly MethodInfo htObjectPushMeth   = typeof (HeapTrackerObject).GetMethod ("Push", new Type[0]);

        public TokenTypeObject (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeObject (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (object); }
        public override string ToString () { return "object"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarObjectsFieldInfo;
            declVar.vTableIndex = arSizes.iasObjects ++;
        }
        public override Type ToHeapTrackerType () { return typeof (HeapTrackerObject); }
        public override ConstructorInfo GetHeapTrackerCtor () { return htObjectCtor; }
        public override MethodInfo GetHeapTrackerPopMeth ()   { return htObjectPopMeth; }
        public override MethodInfo GetHeapTrackerPushMeth ()  { return htObjectPushMeth; }
    }
    public class TokenTypeRot : TokenType {
        private static readonly FieldInfo iarRotationsFieldInfo = typeof (XMRInstArrays).GetField ("iarRotations");

        public TokenTypeRot (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeRot (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (LSL_Rotation); }
        public override string ToString () { return "rotation"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarRotationsFieldInfo;
            declVar.vTableIndex = arSizes.iasRotations ++;
        }
    }
    public class TokenTypeStr : TokenType {
        private static readonly FieldInfo iarStringsFieldInfo = typeof (XMRInstArrays).GetField ("iarStrings");
        private static readonly ConstructorInfo htStringCtor  = typeof (HeapTrackerString).GetConstructor (new Type [] { typeof (XMRInstAbstract) });
        private static readonly MethodInfo htStringPopMeth    = typeof (HeapTrackerString).GetMethod ("Pop", new Type[] { typeof (string) });
        private static readonly MethodInfo htStringPushMeth   = typeof (HeapTrackerString).GetMethod ("Push", new Type[0]);

        public TokenTypeStr (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeStr (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (string); }
        public override string ToString () { return "string"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarStringsFieldInfo;
            declVar.vTableIndex = arSizes.iasStrings ++;
        }
        public override Type ToHeapTrackerType () { return typeof (HeapTrackerString); }
        public override ConstructorInfo GetHeapTrackerCtor () { return htStringCtor; }
        public override MethodInfo GetHeapTrackerPopMeth ()   { return htStringPopMeth; }
        public override MethodInfo GetHeapTrackerPushMeth ()  { return htStringPushMeth; }
    }
    public class TokenTypeUndef : TokenType {  // for the 'undef' constant, ie, null object pointer
        public TokenTypeUndef (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeUndef (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (object); }
        public override string ToString () { return "undef"; }
    }
    public class TokenTypeVec : TokenType {
        private static readonly FieldInfo iarVectorsFieldInfo = typeof (XMRInstArrays).GetField ("iarVectors");

        public TokenTypeVec (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { } 
        public TokenTypeVec (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (LSL_Vector); }
        public override string ToString () { return "vector"; }
        public override void AssignVarSlot (TokenDeclVar declVar, XMRInstArSizes arSizes)
        {
            declVar.vTableArray = iarVectorsFieldInfo;
            declVar.vTableIndex = arSizes.iasVectors ++;
        }
    }
    public class TokenTypeVoid : TokenType {  // used only for function/method return types
        public TokenTypeVoid (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeVoid (Token original) : base (original) { }
        public override Type ToSysType () { return typeof (void); }
        public override string ToString () { return "void"; }
    }

    public class TokenTypeLSLFloat : TokenTypeFloat {
        public TokenTypeLSLFloat (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeLSLFloat (Token original) : base (original) { }
        public override Type ToLSLWrapType () { return typeof (LSL_Float); }
    }
    public class TokenTypeLSLInt : TokenTypeInt {
        public TokenTypeLSLInt (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeLSLInt (Token original) : base (original) { }
        public override Type ToLSLWrapType () { return typeof (LSL_Integer); }
    }
    public class TokenTypeLSLKey : TokenTypeKey {
        public TokenTypeLSLKey (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeLSLKey (Token original) : base (original) { }
        public override Type ToLSLWrapType () { return typeof (LSL_Key); }
    }
    public class TokenTypeLSLString : TokenTypeStr {
        public TokenTypeLSLString (TokenErrorMessage emsg, string file, int line, int posn) : base (emsg, file, line, posn) { }
        public TokenTypeLSLString (Token original) : base (original) { }
        public override Type ToLSLWrapType () { return typeof (LSL_String); }
    }
}