/
table.cpp
1854 lines (1754 loc) · 59.2 KB
/
table.cpp
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
// vim:ts=4:sw=4:
// Interactive BASIC Compiler Project
// File: table.cpp - contains operator/command/function table
// Copyright (C) 2010-2011 Thunder422
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// For a copy of the GNU General Public License,
// see <http://www.gnu.org/licenses/>.
//
//
// Change History:
//
// 2010-02-18 initial release
//
// 2010-03-01 renamed ImCommand_TokenType to ImmCmd_TokenType
//
// 2010-03-06 changed None_DataType to String_DataType for the internal string
// functions
//
// 2010-03-10 corrected multiple entry for operators <, <=, and <>
// (was OneChar, changed to TwoChar)
//
// 2010-03-11 split IntFunc_TokenType into IntFuncN_TokenType and
// IntFuncP_TokenType; changed tables entries accordingly
//
// 2010-03-17 added data for new unary_code field with all set to Null_Code
// except for Sub_Code and Not_Code
// added new table entries for Null_Code, Neg_Code and EOL_Code
//
// 2010-03-20 added precedence values to the table entries
//
// 2010-03-21 for Neg_Code temporarily replaced "-" with "Neq" for testing
// and changed unary_code from Null_Code to Neq_Code
//
// 2010-03-25 added unary code for (, changed precedence values for ( & )
//
// 2010-04-02 changed precedence value in comma entry
// corrected name for VAL( from "Val(" to "VAL("
// for operators, name is actual (recreator) output string,
// name2 is debug output string (only affects Neg for now)
//
// 2010-04-04 added values for number of arguments variable
// added entry for Asc2_Code
// replaced Mid_Code entry Mid2_Code and Mid3_Code entries
// replaced Instr_Code entry Instr2_Code and Instr3_Code entries
// added Multiple_Flag for Asc_Code, Mid2_Code and Instr2_Code
// implemented new number of arguments search function
//
// 2010-04-11 added table entries for assignment operators
// set correct precedence for internal functions
// removed unnecessary 0 initializers from entries
//
// 2010-04-24 added values for the number of operands to the operator entries
// added values for new operand_datatype[] and assoc_code[] arrays
// corrected data type for many operators and internal functions
// added entries for the associated codes
// moved the Null_Code to the end of the table
// added entries for FRAC, CDBL, CvtDbl and CvtDbl
//
// 2010-05-03 began to add support for initialization of expression
// information structures for the table entries
// 2010-05-04 updated table entries for the expression information structures
// 2010-05-05 modified the assignment operator entries for data type handling
// added entries for associated assignment operators
// added Operands and AssocCode macros
// 2010-05-08 added expression information structures for unary operators
//
// 2010-05-15 modified codes that return string to return TmpStr (Chr, Repeat,
// Space, Str, CatStr, and StrInt) - new ExprInfos were added
// added String_Flag to all codes that have string operands
//
// 2010-05-19 changed data type of LEFT, MID2, MID3 and RIGHT to SubStr
// added new associated code AssignSubStr_Code to Assign_Code along
// with their new table entries
// 2010-05-20 added code to check if the Max_Operands and Max_Assoc_Codes
// agree with the tables entries, reporting errors if not
//
// 2010-05-22 removed String_Flag from codes with string operands and replaced
// this with the automatic setting the flag by looking at the
// entries during table initialization
// added new associated code AssignListMixStr along with its new
// table entry
//
// 2010-05-27 changed precedence values for CloseParen_Code and Comma_Code
// from 4 to 6 so commands are not emptied from the hold stack
// added precedence value of 4 (and NUll_Flag) to all commands
// 2010-05-28 added value for new token_mode to Let_Code
// added values for new token_handler to Eq_Code, CloseParen_Code,
// Comma_Code, and EOL_Code
// 2010-05-29 added Hidden_Flag to CvtInt_Code and CvtDbl_Code
//
// 2010-06-01 added print-only function support (Spc_Code and Tab_Code)
// initiated PRINT command development
// 2010-06-02 added data type specific print hidden code entries
// changed precedence and added token handler value to SemiColon
// 2010-06-05 added command handler function pointers for PRINT and assign
// table entries
// 2010-06-06 added end expression flag to Comma, SemiColon and EOL
// 2010-06-09 swapped table entries of MID$, INSTR, and ASC so that the larger
// number of arguments entry is first, which is necessary for the
// new number of arguments checking at comma
// 2010-06-13 added command handler to Let entry
// 2010-06-14 removed AssignList_Flag from AssignList table entries
//
// 2010-06-25 Replaced TableError with generic Error template
// renamed TableSearch enum to SearchType
// 2010-06-26 added end statment flag to EOL
// 2010-06-29 added expr_type value to PRINT code
// 2010-07-02 changed assign and assign list operators expression information
// from two operands to one - the assign operators are no longer
// handled by the standard operator routines
//
// 2010-07-18 added second associate code index to support checking each
// operand when first processed
// 2010-08-10 swapped function with multiple arguments (ASC, INSTR, MID) back
// where least number of argument form is first
// validate multiple argument codes (ASC, INSTR, MID)
// 2010-12-23 automatically generate new table entry number of string
// arguments
//
// 2010-12-29 added Print_Flag to the print type codes
// 2011-01-05 removed expr_type from table entries, added datatype values
// 2011-01-07 moved all datatype values from exprinfo to main entry
// updated all ExprInfo constants (and removed duplicates)
// 2011-02-03 started implementing associated entries for TmpStr type
// 2011-02-04 continue implementing TmpStr associated entries
// 2011-02-05 changed all AssocCode2 macro calls with 0 for index with the
// AssocCode macro call, which is the same for index = 0
// changed table initialization to not count temporary strings
// changed table initialization to allow assoc2_index to equal
// nassoc_codes so that no associated codes are searched for
// matching the second operand if not desired (for assigns)
// changed assign string code entries to have their own expression
// info instances because the first string operand does not get
// get counted for the number of strings
// modified table initialization to not could the first string
// operand if reference flag is set (assignment operators)
//
// 2011-02-26 removed code from first memory in table entries to comment at
// beginning of entry, which is used by codes.awk to generated
// codes.h containing the Code enumeration
// moved Null_Code entry from end to beginning so that Null_Code
// enumeration value will be zero
// removed table index/code duplicate and missing checking (not
// necessary since codes are new generated directly from table)
// added bracketing around immediate commands
// updated search() functions to return Code enumeration value
// 2011-03-01 started INPUT command handler, added INPUT PROMPT table entry,
// add InputBegin tale entries
// removed String flags - automatically set in Table::Table()
// 2011-03-19 added input assign codes plus their associated code lists,
// which sets the input parse codes as second associated codes
// renamed EndStatment_Flag to EndStmt_Flag
//
// 2011-03-26 corrected Assoc2Code_ErrorType error
//
// 2012-10-28 Table::Table() now Table::initialize() and instead of throwing
// an exception for any errors found, returns a list of error
// strings as a QStringList (no longer uses Error Template)
// 2012-11-01 replaced some char* with QStringRef
// removed immediate commands from table
// 2012-11-04 moved all table specific (private) definitions from table.h
// moved code for access functions from table.h
// renamed variables and functions to Qt style naming
// made all array initalizers static
// changed the rest of char* to QString, removed use of strcmp()
// 2012-11-04 modified table class so that only one instance can be created
#include <QChar>
#include <QString>
#include "table.h"
#include "commandhandlers.h"
#include "tokenhandlers.h"
const int MaxOperands = 3;
// this value contains the maximum number of operands
// (arguments) for any operator or internal function (there are currently
// no internal function with more than 3 arguments)
const int MaxAssocCodes = 4;
// this value contains the maximum number of associated codes,
// codes in additional to the main code for different possible data types
// for the code (no code currently has more the 4 total codes)
// expression information for operators and internal functions
struct ExprInfo
{
Code m_unaryCode; // operator unary code (Null_Code if none)
short m_nOperands; // number of operands (operators/functions)
short m_nAssocCodes; // number of associated codes
short m_assoc2Index; // second operand assoc codes start index
short m_nStrings; // number of string arguments
DataType *m_operandDataType; // data type of each operand
Code *m_assocCode; // associated codes
ExprInfo(Code unaryCode = Null_Code, short nOperands = 0,
DataType *operandDataType = NULL, short nAssocCodes = 0,
short assoc2Index = 0, Code *assocCode = NULL) :
m_unaryCode(unaryCode), m_nOperands(nOperands),
m_operandDataType(operandDataType), m_nAssocCodes(nAssocCodes),
m_assoc2Index(assoc2Index), m_assocCode(assocCode), m_nStrings(0)
// default for m_nStrings; will be filled in later
{
}
};
struct TableEntry
{
TokenType type; // type of token for entry
Multiple multiple; // multiple word command/character operator
const QString name; // name for table entry
const QString name2; // name of second word of command
int flags; // flags for entry
int precedence; // precedence of code
DataType dataType; // next expression data type for command
ExprInfo *exprInfo; // expression info pointer (NULL for none)
TokenHandler tokenHandler; // translator token handler pointer
TokenMode tokenMode; // next token mode for command
CommandHandler commandHandler; // translator command handler pointer
};
Table *Table::m_instance; // pointer to single table instance
// this macro produces two entries for the ExprInfo constructor,
// one for the number of operands, one for the pointer to the
// operand data type array
#define Operands(type) (sizeof(type ## _OperandArray) \
/ sizeof(type ## _OperandArray[0])), type ## _OperandArray
// macro produces associated code fields for table entries
#define AssocCode(code) (sizeof(code ## _AssocCode) \
/ sizeof(code ## _AssocCode[0])), 0, code ## _AssocCode
// macro produces associated code fields with secondary index for table entries
#define AssocCode2(code, index2) (sizeof(code ## _AssocCode) \
/ sizeof(code ## _AssocCode[0])), index2, code ## _AssocCode
// operand data type arrays
static DataType Dbl_OperandArray[] = {
Double_DataType
};
static DataType DblDbl_OperandArray[] = {
Double_DataType, Double_DataType
};
static DataType DblInt_OperandArray[] = {
Double_DataType, Integer_DataType
};
static DataType Int_OperandArray[] = {
Integer_DataType
};
static DataType IntDbl_OperandArray[] = {
Integer_DataType, Double_DataType
};
static DataType IntInt_OperandArray[] = {
Integer_DataType, Integer_DataType
};
static DataType Str_OperandArray[] = {
String_DataType
};
static DataType StrInt_OperandArray[] = {
String_DataType, Integer_DataType
};
static DataType StrIntInt_OperandArray[] = {
String_DataType, Integer_DataType, Integer_DataType
};
static DataType StrStr_OperandArray[] = {
String_DataType, String_DataType
};
static DataType StrTmp_OperandArray[] = {
String_DataType, TmpStr_DataType
};
static DataType StrStrInt_OperandArray[] = {
String_DataType, String_DataType, Integer_DataType
};
static DataType StrTmpInt_OperandArray[] = {
String_DataType, TmpStr_DataType, Integer_DataType
};
static DataType Sub_OperandArray[] = {
SubStr_DataType
};
static DataType SubStr_OperandArray[] = {
SubStr_DataType, String_DataType
};
static DataType SubTmp_OperandArray[] = {
SubStr_DataType, TmpStr_DataType
};
static DataType Tmp_OperandArray[] = {
TmpStr_DataType
};
static DataType TmpInt_OperandArray[] = {
TmpStr_DataType, Integer_DataType
};
static DataType TmpStr_OperandArray[] = {
TmpStr_DataType, String_DataType
};
static DataType TmpStrInt_OperandArray[] = {
TmpStr_DataType, String_DataType, Integer_DataType
};
static DataType TmpTmp_OperandArray[] = {
TmpStr_DataType, TmpStr_DataType
};
static DataType TmpTmpInt_OperandArray[] = {
TmpStr_DataType, TmpStr_DataType, Integer_DataType
};
// associated code data type arrays
static Code Abs_AssocCode[] = {AbsInt_Code};
static Code Add_AssocCode[] = {
AddI1_Code, CatStr_Code, CatStrT1_Code, AddI2_Code
};
static Code AddI1_AssocCode[] = {AddInt_Code};
static Code Asc_AssocCode[] = {AscTmp_Code};
static Code Asc2_AssocCode[] = {Asc2Tmp_Code};
static Code Assign_AssocCode[] = {
AssignInt_Code, AssignStr_Code, AssignSubStr_Code
};
static Code AssignStr_AssocCode[] = {AssignTmp_Code};
static Code AssignSubStr_AssocCode[] = {AssignSubTmp_Code};
static Code AssignList_AssocCode[] = {
AssignListInt_Code, AssignListStr_Code, AssignListMix_Code
};
static Code AssignListStr_AssocCode[] = {AssignListTmp_Code};
static Code AssignListMix_AssocCode[] = {AssignListMixTmp_Code};
static Code CatStr_AssocCode[] = {CatStrT2_Code};
static Code CatStrT1_AssocCode[] = {CatStrTT_Code};
static Code Div_AssocCode[] = {DivI1_Code, DivI2_Code};
static Code DivI1_AssocCode[] = {DivInt_Code};
static Code Eq_AssocCode[] = {
EqI1_Code, EqStr_Code, EqStrT1_Code, EqI2_Code
};
static Code EqI1_AssocCode[] = {EqInt_Code};
static Code EqStr_AssocCode[] = {EqStrT2_Code};
static Code EqStrT1_AssocCode[] = {EqStrTT_Code};
static Code Gt_AssocCode[] = {
GtI1_Code, GtStr_Code, GtStrT1_Code, GtI2_Code
};
static Code GtI1_AssocCode[] = {GtInt_Code};
static Code GtStr_AssocCode[] = {GtStrT2_Code};
static Code GtStrT1_AssocCode[] = {GtStrTT_Code};
static Code GtEq_AssocCode[] = {
GtEqI1_Code, GtEqStr_Code, GtEqStrT1_Code, GtEqI2_Code
};
static Code GtEqI1_AssocCode[] = {GtEqInt_Code};
static Code GtEqStr_AssocCode[] = {GtEqStrT2_Code};
static Code GtEqStrT1_AssocCode[] = {GtEqStrTT_Code};
static Code InputBeginStr_AssocCode[] = {InputBeginTmp_Code};
static Code InputAssign_AssocCode[] = {
InputAssignInt_Code, InputAssignStr_Code, InputParse_Code
};
static Code InputAssignInt_AssocCode[] = {InputParseInt_Code};
static Code InputAssignStr_AssocCode[] = {InputParseStr_Code};
static Code Instr2_AssocCode[] = {Instr2T1_Code, Instr2T2_Code};
static Code Instr2T1_AssocCode[] = {Instr2TT_Code};
static Code Instr3_AssocCode[] = {Instr3T1_Code, Instr3T2_Code};
static Code Instr3T1_AssocCode[] = {Instr3TT_Code};
static Code Len_AssocCode[] = {LenTmp_Code};
static Code Lt_AssocCode[] = {
LtI1_Code, LtStr_Code, LtStrT1_Code, LtI2_Code
};
static Code LtI1_AssocCode[] = {LtInt_Code};
static Code LtStr_AssocCode[] = {LtStrT2_Code};
static Code LtStrT1_AssocCode[] = {LtStrTT_Code};
static Code LtEq_AssocCode[] = {
LtEqI1_Code, LtEqStr_Code, LtEqStrT1_Code, LtEqI2_Code
};
static Code LtEqI1_AssocCode[] = {LtEqInt_Code};
static Code LtEqStr_AssocCode[] = {LtEqStrT2_Code};
static Code LtEqStrT1_AssocCode[] = {LtEqStrTT_Code};
static Code Mod_AssocCode[] = {ModI1_Code, ModI2_Code};
static Code ModI1_AssocCode[] = {ModInt_Code};
static Code Mul_AssocCode[] = {MulI1_Code, MulI2_Code};
static Code MulI1_AssocCode[] = {MulInt_Code};
static Code Neg_AssocCode[] = {NegInt_Code};
static Code NotEq_AssocCode[] = {
NotEqI1_Code, NotEqStr_Code, NotEqStrT1_Code, NotEqI2_Code
};
static Code NotEqI1_AssocCode[] = {NotEqInt_Code};
static Code NotEqStr_AssocCode[] = {NotEqStrT2_Code};
static Code NotEqStrT1_AssocCode[] = {NotEqStrTT_Code};
static Code Power_AssocCode[] = {PowerI1_Code, PowerMul_Code};
static Code PowerI1_AssocCode[] = {PowerInt_Code};
static Code Print_AssocCode[] = {
PrintInt_Code, PrintStr_Code, PrintTmp_Code
};
static Code Repeat_AssocCode[] = {RepeatTmp_Code};
static Code RndArgs_AssocCode[] = {RndArgInt_Code};
static Code Sgn_AssocCode[] = {SgnInt_Code};
static Code Str_AssocCode[] = {StrInt_Code};
static Code Sub_AssocCode[] = {SubI1_Code, SubI2_Code};
static Code SubI1_AssocCode[] = {SubInt_Code};
static Code Val_AssocCode[] = {ValTmp_Code};
// standard expression information structures
static ExprInfo Dbl_ExprInfo(Null_Code, Operands(Dbl));
static ExprInfo DblDbl_ExprInfo(Null_Code, Operands(DblDbl));
static ExprInfo DblInt_ExprInfo(Null_Code, Operands(DblInt));
static ExprInfo Int_ExprInfo(Null_Code, Operands(Int));
static ExprInfo IntInt_ExprInfo(Null_Code, Operands(IntInt));
static ExprInfo Str_ExprInfo(Null_Code, Operands(Str));
static ExprInfo StrInt_ExprInfo(Null_Code, Operands(StrInt));
static ExprInfo StrStr_ExprInfo(Null_Code, Operands(StrStr)); //?
static ExprInfo StrStrInt_ExprInfo(Null_Code, Operands(StrStrInt));
static ExprInfo StrTmp_ExprInfo(Null_Code, Operands(StrTmp));
static ExprInfo Assign_StrTmp_ExprInfo(Null_Code, Operands(StrTmp));
static ExprInfo StrTmpInt_ExprInfo(Null_Code, Operands(StrTmpInt));
static ExprInfo Assign_SubTmp_ExprInfo(Null_Code, Operands(SubTmp));
static ExprInfo Tmp_ExprInfo(Null_Code, Operands(Tmp));
static ExprInfo TmpInt_ExprInfo(Null_Code, Operands(TmpInt));
static ExprInfo TmpStr_ExprInfo(Null_Code, Operands(TmpStr));
static ExprInfo TmpStrInt_ExprInfo(Null_Code, Operands(TmpStrInt));
static ExprInfo TmpTmp_ExprInfo(Null_Code, Operands(TmpTmp));
static ExprInfo TmpTmpInt_ExprInfo(Null_Code, Operands(TmpTmpInt));
static ExprInfo StrIntInt_ExprInfo(Null_Code, Operands(StrIntInt));
static ExprInfo Sub_ExprInfo(Null_Code, Operands(Sub));
// code enumeration names in comments after opening brace
// (code enumeration generated from these by enums.awk)
static TableEntry tableEntries[] =
{
// Null_Code entry at beginning so Null_Code == 0
{ // Null_Code
Operator_TokenType
},
//***********************
// BEGIN PLAIN WORDS
//***********************
{ // BegPlainWord_Code
Error_TokenType
},
//--------------
// Commands
//--------------
{ // Let_Code
Command_TokenType, OneWord_Multiple,
"LET", NULL, Null_Flag, 4, None_DataType, NULL, NULL,
Assignment_TokenMode, Let_CmdHandler
},
{ // Print_Code
Command_TokenType, OneWord_Multiple,
"PRINT", NULL, Null_Flag, 4, None_DataType, NULL, NULL,
Expression_TokenMode, Print_CmdHandler
},
{ // Input_Code
Command_TokenType, TwoWord_Multiple,
"INPUT", NULL, Null_Flag, 4, None_DataType, NULL, NULL,
Reference_TokenMode, Input_CmdHandler
},
{ // InputPrompt_Code
Command_TokenType, TwoWord_Multiple,
"INPUT", "PROMPT", Null_Flag, 4, String_DataType, NULL, NULL,
Expression_TokenMode, Input_CmdHandler
},
{ // Dim_Code
Command_TokenType, OneWord_Multiple,
"DIM", NULL, Null_Flag, 4, None_DataType
},
{ // Def_Code
Command_TokenType, OneWord_Multiple,
"DEF", NULL, Null_Flag, 4, None_DataType
},
{ // Rem_Code
Command_TokenType, OneWord_Multiple,
"REM", NULL, Null_Flag, 4, None_DataType
},
{ // If_Code
Command_TokenType, OneWord_Multiple,
"IF", NULL, Null_Flag, 4, None_DataType
},
{ // Then_Code
Command_TokenType, OneWord_Multiple,
"THEN", NULL, Null_Flag, 4, None_DataType
},
{ // Else_Code
Command_TokenType, OneWord_Multiple,
"ELSE", NULL, Null_Flag, 4, None_DataType
},
{ // End_Code
Command_TokenType, TwoWord_Multiple,
"END", NULL, Null_Flag, 4, None_DataType
},
{ // EndIf_Code
Command_TokenType, TwoWord_Multiple,
"END", "IF", Null_Flag, 4, None_DataType
},
{ // For_Code
Command_TokenType, OneWord_Multiple,
"FOR", NULL, Null_Flag, 4, None_DataType
},
{ // To_Code
Command_TokenType, OneWord_Multiple,
"TO", NULL, Null_Flag, 4, None_DataType
},
{ // Step_Code
Command_TokenType, OneWord_Multiple,
"STEP", NULL, Null_Flag, 4, None_DataType
},
{ // Next_Code
Command_TokenType, OneWord_Multiple,
"NEXT", NULL, Null_Flag, 4, None_DataType
},
{ // Do_Code
Command_TokenType, TwoWord_Multiple,
"DO", NULL, Null_Flag, 4, None_DataType
},
{ // DoWhile_Code
Command_TokenType, TwoWord_Multiple,
"DO", "WHILE", Null_Flag, 4, None_DataType
},
{ // DoUntil_Code
Command_TokenType, TwoWord_Multiple,
"DO", "UNTIL", Null_Flag, 4, None_DataType
},
{ // While_Code
Command_TokenType, TwoWord_Multiple,
"WHILE", NULL, Null_Flag, 4, None_DataType
},
{ // Until_Code
Command_TokenType, TwoWord_Multiple,
"UNTIL", NULL, Null_Flag, 4, None_DataType
},
{ // Loop_Code
Command_TokenType, TwoWord_Multiple,
"LOOP", NULL, Null_Flag, 4, None_DataType
},
{ // LoopWhile_Code
Command_TokenType, TwoWord_Multiple,
"LOOP", "WHILE", Null_Flag, 4, None_DataType
},
{ // LoopUntil_Code
Command_TokenType, TwoWord_Multiple,
"LOOP", "UNTIL", Null_Flag, 4, None_DataType
},
//-----------------------------------------
// Internal Functions (No Parentheses)
//-----------------------------------------
{ // Rnd_Code
IntFuncN_TokenType, OneWord_Multiple,
"RND", NULL, Null_Flag, 2, Double_DataType, new ExprInfo()
},
//--------------------
// Word Operators
//--------------------
{ // Mod_Code
Operator_TokenType, OneWord_Multiple,
"MOD", NULL, Null_Flag, 42, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Mod, 1))
},
{ // And_Code
Operator_TokenType, OneWord_Multiple,
"AND", NULL, Null_Flag, 18, Integer_DataType, &IntInt_ExprInfo
},
{ // Or_Code
Operator_TokenType, OneWord_Multiple,
"OR", NULL, Null_Flag, 14, Integer_DataType, &IntInt_ExprInfo
},
{ // Not_Code
Operator_TokenType, OneWord_Multiple,
"NOT", NULL, Null_Flag, 20, Integer_DataType,
new ExprInfo(Not_Code, Operands(Int))
},
{ // Eqv_Code
Operator_TokenType, OneWord_Multiple,
"EQV", NULL, Null_Flag, 12, Integer_DataType, &IntInt_ExprInfo
},
{ // Imp_Code
Operator_TokenType, OneWord_Multiple,
"IMP", NULL, Null_Flag, 10, Integer_DataType, &IntInt_ExprInfo
},
{ // Xor_Code
Operator_TokenType, OneWord_Multiple,
"XOR", NULL, Null_Flag, 16, Integer_DataType, &IntInt_ExprInfo
},
//*********************
// END PLAIN WORDS
//*********************
{ // EndPlainWord_Code
Error_TokenType
},
//*****************************
// BEGIN PARENTHESES WORDS
//*****************************
{ // BegParenWord_Code
Error_TokenType
},
//--------------------------------------
// INTERNAL FUNCTIONS (Parentheses)
//--------------------------------------
{ // Abs_Code
IntFuncP_TokenType, OneWord_Multiple,
"ABS(", NULL, Null_Flag, 2, Double_DataType,
new ExprInfo(Null_Code, Operands(Dbl), AssocCode(Abs))
},
{ // Fix_Code
IntFuncP_TokenType, OneWord_Multiple,
"FIX(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Frac_Code
IntFuncP_TokenType, OneWord_Multiple,
"FRAC(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Int_Code
IntFuncP_TokenType, OneWord_Multiple,
"INT(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // RndArg_Code
IntFuncP_TokenType, OneWord_Multiple,
"RND(", NULL, Null_Flag, 2, Double_DataType,
new ExprInfo(Null_Code, Operands(Dbl), AssocCode(RndArgs))
},
{ // Sgn_Code
IntFuncP_TokenType, OneWord_Multiple,
"SGN(", NULL, Null_Flag, 2, Double_DataType,
new ExprInfo(Null_Code, Operands(Dbl), AssocCode(Sgn))
},
{ // Cint_Code
IntFuncP_TokenType, OneWord_Multiple,
"CINT(", NULL, Null_Flag, 2, Integer_DataType, &Dbl_ExprInfo
},
{ // Cdbl_Code
IntFuncP_TokenType, OneWord_Multiple,
"CDBL(", NULL, Null_Flag, 2, Double_DataType, &Int_ExprInfo
},
{ // Sqr_Code
IntFuncP_TokenType, OneWord_Multiple,
"SQR(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Atn_Code
IntFuncP_TokenType, OneWord_Multiple,
"ATN(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Cos_Code
IntFuncP_TokenType, OneWord_Multiple,
"COS(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Sin_Code
IntFuncP_TokenType, OneWord_Multiple,
"SIN(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Tan_Code
IntFuncP_TokenType, OneWord_Multiple,
"TAN(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Exp_Code
IntFuncP_TokenType, OneWord_Multiple,
"EXP(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Log_Code
IntFuncP_TokenType, OneWord_Multiple,
"LOG(", NULL, Null_Flag, 2, Double_DataType, &Dbl_ExprInfo
},
{ // Tab_Code
IntFuncP_TokenType, OneWord_Multiple,
"TAB(", NULL, Print_Flag, 2, None_DataType, &Int_ExprInfo
},
{ // Spc_Code
IntFuncP_TokenType, OneWord_Multiple,
"SPC(", NULL, Print_Flag, 2, None_DataType, &Int_ExprInfo
},
{ // Asc_Code
IntFuncP_TokenType, OneWord_Multiple,
"ASC(", NULL, Multiple_Flag, 2, Integer_DataType,
new ExprInfo(Null_Code, Operands(Str), AssocCode(Asc))
},
{ // Asc2_Code
IntFuncP_TokenType, OneWord_Multiple,
"ASC(", "ASC2(", Null_Flag, 2, Integer_DataType,
new ExprInfo(Null_Code, Operands(StrInt), AssocCode(Asc2))
},
{ // Chr_Code
IntFuncP_TokenType, OneWord_Multiple,
"CHR$(", NULL, Null_Flag, 2, TmpStr_DataType, &Int_ExprInfo
},
{ // Instr2_Code
IntFuncP_TokenType, OneWord_Multiple,
"INSTR(", "INSTR2(", Multiple_Flag, 2, Integer_DataType,
new ExprInfo(Null_Code, Operands(StrStr), AssocCode2(Instr2, 1))
},
{ // Instr3_Code
IntFuncP_TokenType, OneWord_Multiple,
"INSTR(", "INSTR3(", Null_Flag, 2, Integer_DataType,
new ExprInfo(Null_Code, Operands(StrStrInt), AssocCode2(Instr3, 1))
},
{ // Left_Code
IntFuncP_TokenType, OneWord_Multiple,
"LEFT$(", NULL, Null_Flag, 2, SubStr_DataType, &StrInt_ExprInfo
},
{ // Len_Code
IntFuncP_TokenType, OneWord_Multiple,
"LEN(", NULL, Null_Flag, 2, Integer_DataType,
new ExprInfo(Null_Code, Operands(Str), AssocCode(Len))
},
{ // Mid2_Code
IntFuncP_TokenType, OneWord_Multiple,
"MID$(", "MID2$(", Multiple_Flag, 2, SubStr_DataType, &StrInt_ExprInfo
},
{ // Mid3_Code
IntFuncP_TokenType, OneWord_Multiple,
"MID$(", "MID3$(", Null_Flag, 2, SubStr_DataType, &StrIntInt_ExprInfo
},
{ // Repeat_Code
IntFuncP_TokenType, OneWord_Multiple,
"REPEAT$(", NULL, Null_Flag, 2, TmpStr_DataType,
new ExprInfo(Null_Code, Operands(StrInt), AssocCode(Repeat))
},
{ // Right_Code
IntFuncP_TokenType, OneWord_Multiple,
"RIGHT$(", NULL, Null_Flag, 2, SubStr_DataType, &StrInt_ExprInfo
},
{ // Space_Code
IntFuncP_TokenType, OneWord_Multiple,
"SPACE$(", NULL, Null_Flag, 2, TmpStr_DataType, &Int_ExprInfo
},
{ // Str_Code
IntFuncP_TokenType, OneWord_Multiple,
"STR$(", NULL, Null_Flag, 2, TmpStr_DataType,
new ExprInfo(Null_Code, Operands(Dbl), AssocCode(Str))
},
{ // Val_Code
IntFuncP_TokenType, OneWord_Multiple,
"VAL(", NULL, Null_Flag, 2, Double_DataType, &Str_ExprInfo
},
//***************************
// END PARENTHESES WORDS
//***************************
{ // EndParenWord_Code
Error_TokenType
},
//***************************
// BEGIN DATA TYPE WORDS
//***************************
{ // BegDataTypeWord_Code
Error_TokenType
},
// Currently None
//*************************
// END DATA TYPE WORDS
//*************************
{ // EndDataTypeWord_Code
Error_TokenType
},
//*******************
// BEGIN SYMBOLS
//*******************
{ // BegSymbol_Code
Error_TokenType
},
//----------------------
// Symbol Operators
//----------------------
{ // Add_Code
Operator_TokenType, OneChar_Multiple,
"+", NULL, Null_Flag, 40, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Add, 3))
},
{ // Sub_Code
Operator_TokenType, OneChar_Multiple,
"-", NULL, Null_Flag, 40, Double_DataType,
new ExprInfo(Neg_Code, Operands(DblDbl), AssocCode2(Sub, 1))
},
{ // Mul_Code
Operator_TokenType, OneChar_Multiple,
"*", NULL, Null_Flag, 46, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Mul, 1))
},
{ // Div_Code
Operator_TokenType, OneChar_Multiple,
"/", NULL, Null_Flag, 46, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Div, 1))
},
{ // IntDiv_Code
Operator_TokenType, OneChar_Multiple,
"\\", NULL, Null_Flag, 44, Integer_DataType, &DblDbl_ExprInfo
},
{ // Power_Code
Operator_TokenType, OneChar_Multiple,
"^", NULL, Null_Flag, 50, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Power, 1))
},
{ // Eq_Code
Operator_TokenType, OneChar_Multiple,
"=", NULL, Null_Flag, 30, Integer_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Eq, 3)),
Equal_Handler
},
{ // Gt_Code
Operator_TokenType, TwoChar_Multiple,
">", NULL, Null_Flag, 32, Integer_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Gt, 3))
},
{ // GtEq_Code
Operator_TokenType, TwoChar_Multiple,
">=", NULL, Null_Flag, 32, Integer_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(GtEq, 3))
},
{ // Lt_Code
Operator_TokenType, TwoChar_Multiple,
"<", NULL, Null_Flag, 32, Integer_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Lt, 3))
},
{ // LtEq_Code
Operator_TokenType, TwoChar_Multiple,
"<=", NULL, Null_Flag, 32, Integer_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(LtEq, 3))
},
{ // NotEq_Code
Operator_TokenType, TwoChar_Multiple,
"<>", NULL, Null_Flag, 30, Integer_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(NotEq, 3))
},
{ // OpenParen_Code
Operator_TokenType, OneChar_Multiple,
"(", NULL, Null_Flag, 2, None_DataType,
new ExprInfo(OpenParen_Code)
},
{ // CloseParen_Code
Operator_TokenType, OneChar_Multiple,
")", NULL, Null_Flag, 4, None_DataType, NULL,
CloseParen_Handler
},
{ // Comma_Code
Operator_TokenType, OneChar_Multiple,
",", NULL, EndExpr_Flag, 6, None_DataType,
NULL,//new ExprInfo(Comma_Code),
Comma_Handler
},
{ // SemiColon_Code
Operator_TokenType, OneChar_Multiple,
";", NULL, EndExpr_Flag, 6, None_DataType,
NULL,//new ExprInfo(SemiColon_Code),
SemiColon_Handler
},
{ // Colon_Code
Operator_TokenType, OneChar_Multiple,
":", NULL, Null_Flag, 0, None_DataType
},
{ // RemOp_Code
Operator_TokenType, OneChar_Multiple,
"'", NULL, Null_Flag, 0, None_DataType
},
//*****************
// END SYMBOLS
//*****************
{ // EndSymbol_Code
Error_TokenType
},
//***************************
// MISCELLANEOUS ENTRIES
//***************************
{ // Neg_Code
Operator_TokenType, OneWord_Multiple,
// FIXME temporarily replaced "-" with "Neq" for testing
"-", "Neg", Null_Flag, 48, Double_DataType,
new ExprInfo(Neg_Code, Operands(Dbl), AssocCode(Neg))
},
{ // Assign_Code
Operator_TokenType, OneWord_Multiple,
"=", "Assign", Reference_Flag, 4, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(Assign, 3)),
NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignInt_Code
Operator_TokenType, OneWord_Multiple,
"=", "Assign%", Reference_Flag, 4, Integer_DataType, &IntInt_ExprInfo,
NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignStr_Code
Operator_TokenType, OneWord_Multiple,
"=", "Assign$", Reference_Flag, 4, String_DataType,
new ExprInfo(Null_Code, Operands(StrStr), AssocCode(AssignStr)),
NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignTmp_Code
Operator_TokenType, OneWord_Multiple,
"=", "Assign$T", Reference_Flag, 4, TmpStr_DataType,
&Assign_StrTmp_ExprInfo, NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignSubStr_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignSub$", Reference_Flag, 4, String_DataType,
new ExprInfo(Null_Code, Operands(SubStr), AssocCode(AssignSubStr)),
NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignSubTmp_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignSub$T", Reference_Flag, 4, TmpStr_DataType,
&Assign_SubTmp_ExprInfo, NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignList_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignList", Reference_Flag, 4, Double_DataType,
new ExprInfo(Null_Code, Operands(DblDbl), AssocCode2(AssignList, 3)),
NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignListInt_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignList%", Reference_Flag, 4, Integer_DataType,
&IntInt_ExprInfo, NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignListStr_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignList$", Reference_Flag, 4, String_DataType,
new ExprInfo(Null_Code, Operands(StrStr), AssocCode(AssignListStr)),
NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignListTmp_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignList$T", Reference_Flag, 4, TmpStr_DataType,
&Assign_StrTmp_ExprInfo, NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignListMix_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignListMix$", Reference_Flag, 4, String_DataType,
new ExprInfo(Null_Code, Operands(SubStr), AssocCode(AssignListMix)),
NULL, Null_TokenMode, Assign_CmdHandler
},
{ // AssignListMixTmp_Code
Operator_TokenType, OneWord_Multiple,
"=", "AssignListMix$T", Reference_Flag, 4,
TmpStr_DataType, &Assign_SubTmp_ExprInfo, NULL, Null_TokenMode,
Assign_CmdHandler
},
{ // EOL_Code
Operator_TokenType, OneWord_Multiple,
NULL, NULL, EndExpr_Flag | EndStmt_Flag, 4, None_DataType, NULL,
EndOfLine_Handler
},
{ // AscTmp_Code
IntFuncP_TokenType, OneWord_Multiple,
"ASC(", "ASCT(", Multiple_Flag, 2, Integer_DataType, &Tmp_ExprInfo
},
{ // Asc2Tmp_Code
IntFuncP_TokenType, OneWord_Multiple,
"ASC(", "ASC2T(", Null_Flag, 2, Integer_DataType, &TmpInt_ExprInfo
},
{ // Instr2T1_Code
IntFuncP_TokenType, OneWord_Multiple,
"INSTR(", "INSTR2T1(", Multiple_Flag, 2, Integer_DataType,
new ExprInfo(Null_Code, Operands(TmpStr), AssocCode(Instr2T1))
},
{ // Instr3T1_Code
IntFuncP_TokenType, OneWord_Multiple,
"INSTR(", "INSTR3T1(", Null_Flag, 2, Integer_DataType,
new ExprInfo(Null_Code, Operands(TmpStrInt), AssocCode(Instr3T1))
},
{ // Instr2T2_Code
IntFuncP_TokenType, OneWord_Multiple,
"INSTR(", "INSTR2T2(", Multiple_Flag, 2, Integer_DataType,
&StrTmp_ExprInfo
},
{ // Instr3T2_Code
IntFuncP_TokenType, OneWord_Multiple,
"INSTR(", "INSTR3T2(", Null_Flag, 2, Integer_DataType,
&StrTmpInt_ExprInfo
},
{ // Instr2TT_Code
IntFuncP_TokenType, OneWord_Multiple,
"INSTR(", "INSTR2TT(", Multiple_Flag, 2, Integer_DataType,
&TmpTmp_ExprInfo
},
{ // Instr3TT_Code
IntFuncP_TokenType, OneWord_Multiple,
"INSTR(", "INSTR3TT(", Null_Flag, 2, Integer_DataType,
&TmpTmpInt_ExprInfo
},
{ // LenTmp_Code
IntFuncP_TokenType, OneWord_Multiple,
"LEN(", "LENT(", Null_Flag, 2, Integer_DataType, &Tmp_ExprInfo
},
{ // RepeatTmp_Code