forked from jacobthurman/Castalia-Delphi-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CastaliaPasLex.pas
2797 lines (2528 loc) · 70.4 KB
/
CastaliaPasLex.pas
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
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.mozilla.org/NPL/NPL-1_1Final.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: mwPasLex.PAS, released August 17, 1999.
The Initial Developer of the Original Code is Martin Waldenburg
Portions created by Martin Waldenburg are Copyright (C) 1998, 1999 Martin
Waldenburg.
All Rights Reserved.
Contributor(s): James Jacobson _____________________________________.
Last Modified: mm/dd/yyyy
Current Version: 2.2
Notes: This program is a very fast Pascal tokenizer. I'd like to invite the
Delphi community to develop it further and to create a fully featured Object
Pascal parser.
Modification history:
Daniel Rolf between 20010723 and 20020116
Made ready for Delphi 6
platform
deprecated
varargs
local
Known Issues:
-----------------------------------------------------------------------------}
unit CastaliaPasLex;
{$I CastaliaParserDefines.inc}
interface
uses
//!! pruned uses
SysUtils, Classes, CastaliaPasLexTypes;
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of Integer;
type
TmwBasePasLex = class;
TDirectiveEvent = procedure(Sender: TmwBasePasLex) of object;
PDefineRec = ^TDefineRec;
TDefineRec = record
Defined: Boolean;
StartCount: Integer;
Next: PDefineRec;
end;
TmwBasePasLex = class(TObject)
private
fCommentState: TCommentState;
fOrigin: PChar;
fProcTable: array[#0..#255] of procedure of object;
Run: Integer;
RunAhead: Integer;
TempRun: Integer;
fIdentFuncTable: array[0..191] of function: TptTokenKind of object;
fTokenPos: Integer;
fLineNumber: Integer;
FTokenID: TptTokenKind;
fLinePos: Integer;
fExID: TptTokenKind;
FOnMessage: TMessageEvent;
fOnCompDirect: TDirectiveEvent;
fOnElseDirect: TDirectiveEvent;
fOnEndIfDirect: TDirectiveEvent;
fOnIfDefDirect: TDirectiveEvent;
fOnIfNDefDirect: TDirectiveEvent;
fOnResourceDirect: TDirectiveEvent;
fOnIncludeDirect: TDirectiveEvent;
fOnDefineDirect: TDirectiveEvent;
fOnIfOptDirect: TDirectiveEvent;
fOnIfDirect: TDirectiveEvent;
fOnIfEndDirect: TDirectiveEvent;
fOnElseIfDirect: TDirectiveEvent;
fOnUnDefDirect: TDirectiveEvent;
FDirectiveParamOrigin: PChar;
fAsmCode : Boolean; // DR 2002-01-14
FDefines: TStrings;
FDefineStack: Integer;
FTopDefineRec: PDefineRec;
FUseDefines: Boolean;
function KeyHash: Integer;
function KeyComp(const aKey: string): Boolean;
function Func9: tptTokenKind;
function Func15: TptTokenKind;
function Func19: TptTokenKind;
function Func20: TptTokenKind;
function Func21: TptTokenKind;
function Func23: TptTokenKind;
function Func25: TptTokenKind;
function Func27: TptTokenKind;
function Func28: TptTokenKind;
function Func29: TptTokenKind;
function Func30: TptTokenKind;
function Func32: TptTokenKind;
function Func33: TptTokenKind;
function Func35: TptTokenKind;
function Func36: TptTokenKind;
function Func37: TptTokenKind;
function Func38: TptTokenKind;
function Func39: TptTokenKind;
function Func40: TptTokenKind;
function Func41: TptTokenKind;
{$IFDEF D8_NEWER} //JThurman 2004-03-2003
function Func42: TptTokenKind;
{$ENDIF}
function Func43: TptTokenKind;
function Func44: TptTokenKind;
function Func45: TptTokenKind;
function Func46: TptTokenKind;
function Func47: TptTokenKind;
function Func49: TptTokenKind;
function Func52: TptTokenKind;
function Func54: TptTokenKind;
function Func55: TptTokenKind;
function Func56: TptTokenKind;
function Func57: TptTokenKind;
function Func58: TptTokenKind;
function Func59: TptTokenKind;
function Func60: TptTokenKind;
function Func61: TptTokenKind;
function Func62: TptTokenKind;
function Func63: TptTokenKind;
function Func64: TptTokenKind;
function Func65: TptTokenKind;
function Func66: TptTokenKind;
function Func69: TptTokenKind;
function Func71: TptTokenKind;
{$IFDEF D8_NEWER} //JThurman 2004-03-2003
function Func72: TptTokenKind;
{$ENDIF}
function Func73: TptTokenKind;
function Func75: TptTokenKind;
function Func76: TptTokenKind;
function Func78: TptTokenKind;
function Func79: TptTokenKind;
function Func81: TptTokenKind;
function Func84: TptTokenKind;
function Func85: TptTokenKind;
function Func86: TptTokenKind;
function Func87: TptTokenKind;
function Func88: TptTokenKind;
{$IFDEF D8_NEWER}
function Func89: TptTokenKind; //JThurman 2004-03-03
{$ENDIF}
function Func91: TptTokenKind;
function Func92: TptTokenKind;
function Func94: TptTokenKind;
function Func95: TptTokenKind;
function Func96: TptTokenKind;
function Func97: TptTokenKind;
function Func98: TptTokenKind;
function Func99: TptTokenKind;
function Func100: TptTokenKind;
function Func101: TptTokenKind;
function Func102: TptTokenKind;
function Func103: TptTokenKind;
function Func104: TptTokenKind;
function Func105: TptTokenKind;
function Func106: TptTokenKind;
function Func107: TptTokenKind;
function Func108: TptTokenKind;
function Func112: TptTokenKind;
function Func117: TptTokenKind;
function Func123: TptTokenKind;
function Func126: TptTokenKind;
function Func127: TptTokenKind;
function Func128: TptTokenKind;
function Func129: TptTokenKind;
function Func130: TptTokenKind;
function Func132: TptTokenKind;
function Func133: TptTokenKind;
function Func136: TptTokenKind;
function Func141: TptTokenKind;
function Func143: TptTokenKind;
function Func166: TptTokenKind;
function Func167: TptTokenKind;
function Func168: TptTokenKind;
function Func191: TptTokenKind;
function AltFunc: TptTokenKind;
procedure InitIdent;
function GetPosXY: TTokenPoint; // !! changed to TokenPoint //jdj 7/18/1999
function IdentKind: TptTokenKind;
procedure SetRunPos(Value: Integer);
procedure MakeMethodTables;
procedure AddressOpProc;
{$IFDEF D8_NEWER} //JThurman 2004-04-06
procedure AmpersandOpProc;
{$ENDIF}
procedure AsciiCharProc;
procedure AnsiProc;
procedure BorProc;
procedure BraceCloseProc;
procedure BraceOpenProc;
procedure ColonProc;
procedure CommaProc;
procedure CRProc;
procedure EqualProc;
procedure GreaterProc;
procedure IdentProc;
procedure IntegerProc;
procedure LFProc;
procedure LowerProc;
procedure MinusProc;
procedure NullProc;
procedure NumberProc;
procedure PlusProc;
procedure PointerSymbolProc;
procedure PointProc;
procedure RoundCloseProc;
procedure RoundOpenProc;
procedure SemiColonProc;
procedure SlashProc;
procedure SpaceProc;
procedure SquareCloseProc;
procedure SquareOpenProc;
procedure StarProc;
procedure StringProc;
procedure StringDQProc;
procedure SymbolProc;
procedure UnknownProc;
function GetToken: string;
function GetTokenLen: Integer;
function GetCommentState: Pointer;
function GetCompilerDirective: string;
procedure SetCommentState(const Value: Pointer);
procedure InitLine;
function GetDirectiveKind: TptTokenKind;
function GetDirectiveParam: string;
function GetStringContent: string;
function GetIsJunk: Boolean;
function GetIsSpace: Boolean;
function GetIsOrdIdent: Boolean;
function GetIsRealType: Boolean;
function GetIsStringType: Boolean;
function GetIsVarantType: Boolean;
function GetIsAddOperator: Boolean;
function GetIsMulOperator: Boolean;
function GetIsRelativeOperator: Boolean;
function GetIsCompilerDirective: Boolean;
function GetIsOrdinalType: Boolean;
function GetGenID: TptTokenKind;procedure SetOnElseIfDirect(const Value: TDirectiveEvent);
function IsDefined(const ADefine: string): Boolean;
procedure EnterDefineBlock(ADefined: Boolean);
procedure ExitDefineBlock;
procedure CloneDefinesFrom(ALexer: TmwBasePasLex);
procedure DoProcTable(AChar: Char);
function IsIdentifiers(AChar: Char): Boolean;
function HashValue(AChar: Char): Integer;
protected
procedure SetLine(const Value: string); virtual;
procedure SetOrigin(NewValue: PChar); virtual;
procedure SetOnCompDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnDefineDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnElseDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnEndIfDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnIfDefDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnIfNDefDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnIfOptDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnIncludeDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnResourceDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnUnDefDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnIfDirect(const Value: TDirectiveEvent); virtual;
procedure SetOnIfEndDirect(const Value: TDirectiveEvent); virtual;
public
constructor Create;
destructor Destroy; override;
function CharAhead: Char;
procedure Next;
procedure NextID(ID: TptTokenKind);
procedure NextNoJunk;
procedure NextNoSpace;
procedure Init;
procedure InitFrom(ALexer: TmwBasePasLex);
function FirstInLine: Boolean;
procedure AddDefine(const ADefine: string);
procedure RemoveDefine(const ADefine: string);
procedure ClearDefines;
procedure InitDefines;
property CommentState: Pointer read GetCommentState write SetCommentState;
property CompilerDirective: string read GetCompilerDirective;
property DirectiveParam: string read GetDirectiveParam;
property IsJunk: Boolean read GetIsJunk;
property IsSpace: Boolean read GetIsSpace;
property Line: string write SetLine;
//Note: setting the following two properties does not GO to that line, it just sets the internal counters
property LineNumber: Integer read fLineNumber write fLineNumber;
property LinePos: Integer read fLinePos write fLinePos;
property Origin: PChar read fOrigin write SetOrigin;
property PosXY: TTokenPoint read GetPosXY; // !! changed to TokenPoint //jdj 7/18/1999
property RunPos: Integer read Run write SetRunPos;
property Token: string read GetToken;
property TokenLen: Integer read GetTokenLen;
property TokenPos: Integer read fTokenPos;
property TokenID: TptTokenKind read FTokenID;
property ExID: TptTokenKind read fExID;
property GenID: TptTokenKind read GetGenID;
property StringContent: string read GetStringContent;
property IsOrdIdent: Boolean read GetIsOrdIdent;
property IsOrdinalType: Boolean read GetIsOrdinalType;
property IsRealType: Boolean read GetIsRealType;
property IsStringType: Boolean read GetIsStringType;
property IsVariantType: Boolean read GetIsVarantType;
property IsRelativeOperator: Boolean read GetIsRelativeOperator;
property IsAddOperator: Boolean read GetIsAddOperator;
property IsMulOperator: Boolean read GetIsMulOperator;
property IsCompilerDirective: Boolean read GetIsCompilerDirective;
property OnMessage: TMessageEvent read FOnMessage write FOnMessage;
property OnCompDirect: TDirectiveEvent read fOnCompDirect write SetOnCompDirect;
property OnDefineDirect: TDirectiveEvent read fOnDefineDirect write SetOnDefineDirect;
property OnElseDirect: TDirectiveEvent read fOnElseDirect write SetOnElseDirect;
property OnEndIfDirect: TDirectiveEvent read fOnEndIfDirect write SetOnEndIfDirect;
property OnIfDefDirect: TDirectiveEvent read fOnIfDefDirect write SetOnIfDefDirect;
property OnIfNDefDirect: TDirectiveEvent read fOnIfNDefDirect write SetOnIfNDefDirect;
property OnIfOptDirect: TDirectiveEvent read fOnIfOptDirect write SetOnIfOptDirect;
property OnIncludeDirect: TDirectiveEvent read fOnIncludeDirect write SetOnIncludeDirect;
property OnIfDirect: TDirectiveEvent read fOnIfDirect write SetOnIfDirect;
property OnIfEndDirect: TDirectiveEvent read fOnIfEndDirect write
SetOnIfEndDirect;
property OnElseIfDirect: TDirectiveEvent read fOnElseIfDirect write
SetOnElseIfDirect;
property OnResourceDirect: TDirectiveEvent read fOnResourceDirect write SetOnResourceDirect;
property OnUnDefDirect: TDirectiveEvent read fOnUnDefDirect write SetOnUnDefDirect;
property AsmCode : Boolean read fAsmCode write fAsmCode; // DR 2002-01-14
property DirectiveParamOrigin: pchar read FDirectiveParamOrigin;
property UseDefines: Boolean read FUseDefines write FUseDefines;
end;
TmwPasLex = class(TmwBasePasLex)
private
fAheadLex: TmwBasePasLex;
function GetAheadExID: TptTokenKind;
function GetAheadGenID: TptTokenKind;
function GetAheadToken: string;
function GetAheadTokenID: TptTokenKind;
function GetStatus: TmwPasLexStatus;
procedure SetStatus(const Value: TmwPasLexStatus);
protected
procedure SetLine(const Value: string); override;
procedure SetOrigin(NewValue: PChar); override;
procedure SetOnCompDirect(const Value: TDirectiveEvent); override;
procedure SetOnDefineDirect(const Value: TDirectiveEvent); override;
procedure SetOnElseDirect(const Value: TDirectiveEvent); override;
procedure SetOnEndIfDirect(const Value: TDirectiveEvent); override;
procedure SetOnIfDefDirect(const Value: TDirectiveEvent); override;
procedure SetOnIfNDefDirect(const Value: TDirectiveEvent); override;
procedure SetOnIfOptDirect(const Value: TDirectiveEvent); override;
procedure SetOnIncludeDirect(const Value: TDirectiveEvent); override;
procedure SetOnResourceDirect(const Value: TDirectiveEvent); override;
procedure SetOnUnDefDirect(const Value: TDirectiveEvent); override;
public
constructor Create;
destructor Destroy; override;
procedure InitAhead;
procedure AheadNext;
property AheadLex: TmwBasePasLex read fAheadLex;
property AheadToken: string read GetAheadToken;
property AheadTokenID: TptTokenKind read GetAheadTokenID;
property AheadExID: TptTokenKind read GetAheadExID;
property AheadGenID: TptTokenKind read GetAheadGenID;
property Status: TmwPasLexStatus read GetStatus write SetStatus;
end;
implementation
uses Windows;
procedure MakeIdentTable;
var
I, J: Char;
begin
for I := #0 to #255 do
begin
case I of
'_', '0'..'9', 'a'..'z', 'A'..'Z': Identifiers[I] := True;
else Identifiers[I] := False;
end;
J := UpperCase(I)[1];
case I of
'a'..'z', 'A'..'Z', '_': mHashTable[I] := Ord(J) - 64;
else mHashTable[Char(I)] := 0;
end;
end;
end;
function TmwBasePasLex.CharAhead: Char;
begin
RunAhead := Run;
// while fOrigin[RunAhead] in [#1..#32] do
while (fOrigin[RunAhead] > #0) and (fOrigin[RunAhead] < #33) do
inc(RunAhead);
Result := fOrigin[RunAhead];
end;
procedure TmwBasePasLex.ClearDefines;
var
Frame: PDefineRec;
begin
while FTopDefineRec <> nil do
begin
Frame := FTopDefineRec;
FTopDefineRec := Frame^.Next;
Dispose(Frame);
end;
FDefines.Clear;
FDefineStack := 0;
end;
procedure TmwBasePasLex.CloneDefinesFrom(ALexer: TmwBasePasLex);
var
Frame, LastFrame, SourceFrame: PDefineRec;
begin
ClearDefines;
FDefines.Assign(ALexer.FDefines);
FDefineStack := ALexer.FDefineStack;
Frame := nil;
SourceFrame := ALexer.FTopDefineRec;
while SourceFrame <> nil do
begin
New(Frame);
if FTopDefineRec = nil then
FTopDefineRec := Frame
else
LastFrame^.Next := Frame;
Frame^.Defined := SourceFrame^.Defined;
Frame^.StartCount := SourceFrame^.StartCount;
LastFrame := Frame;
SourceFrame := SourceFrame^.Next;
end;
if Frame <> nil then
Frame^.Next := nil;
// New(StackFrame);
// StackFrame^.Next := FTopDefineRec;
// StackFrame^.Defined := ADefined;
// StackFrame^.StartCount := FDefineStack;
// FTopDefineRec := StackFrame;
// if not ADefined then
// Inc(FDefineStack);
end;
function TmwBasePasLex.GetPosXY: TTokenPoint;
begin //jdj 7/18/1999
// !! changed setting code
Result.X:= FTokenPos - FLinePos;
Result.Y:= FLineNumber;
end;
procedure TmwBasePasLex.InitIdent;
var
I: Integer;
begin
for I := 0 to 191 do
case I of
{$IFDEF D8_NEWER}
9: fIdentFuncTable[I] := Func9;
{$ENDIF}
15: fIdentFuncTable[I] := Func15;
19: fIdentFuncTable[I] := Func19;
20: fIdentFuncTable[I] := Func20;
21: fIdentFuncTable[I] := Func21;
23: fIdentFuncTable[I] := Func23;
25: fIdentFuncTable[I] := Func25;
27: fIdentFuncTable[I] := Func27;
28: fIdentFuncTable[I] := Func28;
29: fIdentFuncTable[I] := Func29;
30: fIdentFuncTable[I] := Func30;
32: fIdentFuncTable[I] := Func32;
33: fIdentFuncTable[I] := Func33;
35: fIdentFuncTable[I] := Func35;
36: fIdentFuncTable[I] := Func36;
37: fIdentFuncTable[I] := Func37;
38: fIdentFuncTable[I] := Func38;
39: fIdentFuncTable[I] := Func39;
40: fIdentFuncTable[I] := Func40;
41: fIdentFuncTable[I] := Func41;
{$IFDEF D8_NEWER} //JThurman 2004-03-2003
42: fIdentFuncTable[I] := Func42;
{$ENDIF}
43: fIdentFuncTable[I] := Func43;
44: fIdentFuncTable[I] := Func44;
45: fIdentFuncTable[I] := Func45;
46: fIdentFuncTable[I] := Func46;
47: fIdentFuncTable[I] := Func47;
49: fIdentFuncTable[I] := Func49;
52: fIdentFuncTable[I] := Func52;
54: fIdentFuncTable[I] := Func54;
55: fIdentFuncTable[I] := Func55;
56: fIdentFuncTable[I] := Func56;
57: fIdentFuncTable[I] := Func57;
58: fIdentFuncTable[I] := Func58;
59: fIdentFuncTable[I] := Func59;
60: fIdentFuncTable[I] := Func60;
61: fIdentFuncTable[I] := Func61;
62: fIdentFuncTable[I] := Func62;
63: fIdentFuncTable[I] := Func63;
64: fIdentFuncTable[I] := Func64;
65: fIdentFuncTable[I] := Func65;
66: fIdentFuncTable[I] := Func66;
69: fIdentFuncTable[I] := Func69;
71: fIdentFuncTable[I] := Func71;
{$IFDEF D8_NEWER} //JThurman 2004-03-2003
72: fIdentFuncTable[I] := Func72;
{$ENDIF}
73: fIdentFuncTable[I] := Func73;
75: fIdentFuncTable[I] := Func75;
76: fIdentFuncTable[I] := Func76;
78: fIdentFuncTable[I] := Func78;
79: fIdentFuncTable[I] := Func79;
81: fIdentFuncTable[I] := Func81;
84: fIdentFuncTable[I] := Func84;
85: fIdentFuncTable[I] := Func85;
86: fIdentFuncTable[I] := Func86;
87: fIdentFuncTable[I] := Func87;
88: fIdentFuncTable[I] := Func88;
{$IFDEF D8_NEWER} //JThurman 2004-03-03
89: fIdentFuncTable[I] := Func89;
{$ENDIF}
91: fIdentFuncTable[I] := Func91;
92: fIdentFuncTable[I] := Func92;
94: fIdentFuncTable[I] := Func94;
95: fIdentFuncTable[I] := Func95;
96: fIdentFuncTable[I] := Func96;
97: fIdentFuncTable[I] := Func97;
98: fIdentFuncTable[I] := Func98;
99: fIdentFuncTable[I] := Func99;
100: fIdentFuncTable[I] := Func100;
101: fIdentFuncTable[I] := Func101;
102: fIdentFuncTable[I] := Func102;
103: fIdentFuncTable[I] := Func103;
104: fIdentFuncTable[I] := Func104;
105: fIdentFuncTable[I] := Func105;
106: fIdentFuncTable[I] := Func106;
107: fIdentFuncTable[I] := Func107;
108: fIdentFuncTable[I] := Func108;
112: fIdentFuncTable[I] := Func112;
117: fIdentFuncTable[I] := Func117;
123: fIdentFuncTable[I] := Func123;
126: fIdentFuncTable[I] := Func126;
127: fIdentFuncTable[I] := Func127;
128: fIdentFuncTable[I] := Func128;
129: fIdentFuncTable[I] := Func129;
130: fIdentFuncTable[I] := Func130;
132: fIdentFuncTable[I] := Func132;
133: fIdentFuncTable[I] := Func133;
136: fIdentFuncTable[I] := Func136;
141: fIdentFuncTable[I] := Func141;
143: fIdentFuncTable[I] := Func143;
166: fIdentFuncTable[I] := Func166;
167: fIdentFuncTable[I] := Func167;
168: fIdentFuncTable[I] := Func168;
191: fIdentFuncTable[I] := Func191;
else fIdentFuncTable[I] := AltFunc;
end;
end;
function TmwBasePasLex.KeyHash: Integer;
begin
Result := 0;
while IsIdentifiers(fOrigin[Run]) do
begin
Inc(Result, HashValue(fOrigin[Run]));
//inc(Result, mHashTable[fOrigin[Run]]);
inc(Run);
end;
end; { KeyHash }
function TmwBasePasLex.KeyComp(const aKey: string): Boolean;
var
I: Integer;
Temp: PChar;
begin
if Length(aKey) = TokenLen then
begin
Temp := fOrigin + fTokenPos;
Result := True;
for i := 1 to TokenLen do
begin
if mHashTable[Temp^] <> mHashTable[aKey[i]] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end
else Result := False;
end; { KeyComp }
function TmwBasePasLex.Func9: tptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Add') then
FExID := ptAdd;
end;
function TmwBasePasLex.Func15: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('If') then Result := ptIf;
end;
function TmwBasePasLex.Func19: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Do') then Result := ptDo else
if KeyComp('And') then Result := ptAnd;
end;
function TmwBasePasLex.Func20: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('As') then Result := ptAs;
end;
function TmwBasePasLex.Func21: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Of') then Result := ptOf else
if KeyComp('At') then fExID := ptAt;
end;
function TmwBasePasLex.Func23: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('End') then Result := ptEnd else
if KeyComp('In') then Result := ptIn;
end;
function TmwBasePasLex.Func25: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Far') then fExID := ptFar;
end;
function TmwBasePasLex.Func27: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Cdecl') then fExID := ptCdecl;
end;
function TmwBasePasLex.Func28: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Read') then fExID := ptRead else
if KeyComp('Case') then Result := ptCase else
if KeyComp('Is') then Result := ptIs;
end;
function TmwBasePasLex.Func29: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('On') then fExID := ptOn;
end;
function TmwBasePasLex.Func30: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Char') then fExID := ptChar;
end;
function TmwBasePasLex.Func32: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('File') then Result := ptFile else
if KeyComp('Label') then Result := ptLabel else
if KeyComp('Mod') then Result := ptMod;
end;
function TmwBasePasLex.Func33: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Or') then Result := ptOr else
if KeyComp('Name') then fExID := ptName else
if KeyComp('Asm') then Result := ptAsm;
end;
function TmwBasePasLex.Func35: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Nil') then Result := ptNil else
if KeyComp('To') then Result := ptTo else
if KeyComp('Div') then Result := ptDiv;
end;
function TmwBasePasLex.Func36: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Real') then fExID := ptReal else
if KeyComp('Real48') then fExID := ptReal48;
end;
function TmwBasePasLex.Func37: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Begin') then Result := ptBegin else
if KeyComp('Break') then fExID := ptBreak;
end;
function TmwBasePasLex.Func38: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Near') then fExID := ptNear;
end;
function TmwBasePasLex.Func39: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('For') then Result := ptFor else
if KeyComp('Shl') then Result := ptShl;
end;
function TmwBasePasLex.Func40: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Packed') then Result := ptPacked;
end;
function TmwBasePasLex.Func41: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Var') then Result := ptVar else
if KeyComp('Else') then Result := ptElse else
if KeyComp('Halt') then fExID := ptHalt;
end;
{$IFDEF D8_NEWER} //JThurman 2004-03-2003
function TmwBasePasLex.Func42: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Final') then
fExID := ptFinal; //TODO: Is this supposed to be an ExID?
end;
{$ENDIF}
function TmwBasePasLex.Func43: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Int64') then fExID := ptInt64
else if KeyComp('local') then fExID := ptLocal;
end;
function TmwBasePasLex.Func44: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Set') then Result := ptSet else
if KeyComp('Package') then fExID := ptPackage;
end;
function TmwBasePasLex.Func45: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Shr') then Result := ptShr;
end;
function TmwBasePasLex.Func46: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('PChar') then fExId := ptPChar
{$IFDEF D8_NEWER} //JThurman 2004-03-19
else
if KeyComp('Sealed') then Result := ptSealed;
{$ELSE}
;
{$ENDIF}
end;
function TmwBasePasLex.Func47: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Then') then Result := ptThen else
if KeyComp('Comp') then fExID := ptComp;
end;
function TmwBasePasLex.Func49: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Not') then Result := ptNot;
end;
function TmwBasePasLex.Func52: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Byte') then fExID := ptByte else
if KeyComp('Raise') then Result := ptRaise else
if KeyComp('Pascal') then fExID := ptPascal;
end;
function TmwBasePasLex.Func54: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Class') then Result := ptClass;
end;
function TmwBasePasLex.Func55: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Object') then Result := ptObject;
end;
function TmwBasePasLex.Func56: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Index') then fExID := ptIndex else
if KeyComp('Out') then fExID := ptOut else // bug in Delphi's documentation: OUT is a directive
if KeyComp('Abort') then fExID := ptAbort;
end;
function TmwBasePasLex.Func57: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('While') then Result := ptWhile else
if KeyComp('Xor') then Result := ptXor else
if KeyComp('Goto') then Result := ptGoto;
end;
function TmwBasePasLex.Func58: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Exit') then fExID := ptExit;
end;
function TmwBasePasLex.Func59: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Safecall') then fExID := ptSafecall else
if KeyComp('Double') then fExID := ptDouble;
end;
function TmwBasePasLex.Func60: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('With') then Result := ptWith else
if KeyComp('Word') then fExID := ptWord;
end;
function TmwBasePasLex.Func61: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Dispid') then fExID := ptDispid;
end;
function TmwBasePasLex.Func62: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Cardinal') then fExID := ptCardinal;
end;
function TmwBasePasLex.Func63: TptTokenKind;
begin
Result := ptIdentifier;
case fOrigin[fTokenPos] of
'P', 'p': if KeyComp('Public') then fExID := ptPublic;
'A', 'a': if KeyComp('Array') then Result := ptArray;
'T', 't': if KeyComp('Try') then Result := ptTry;
'R', 'r': if KeyComp('Record') then Result := ptRecord;
'I', 'i': if KeyComp('Inline') then
begin
Result := ptInline;
fExID := ptInline;
end;
end;
end;
function TmwBasePasLex.Func64: TptTokenKind;
begin
Result := ptIdentifier;
case fOrigin[fTokenPos] of
'B', 'b': if KeyComp('Boolean') then fExID := ptBoolean;
'D', 'd': if KeyComp('DWORD') then fExID := ptDWORD;
'U', 'u': if KeyComp('Uses') then Result := ptUses
else
if KeyComp('Unit') then Result := ptUnit;
{$IFDEF D8_NEWER}
'H', 'h': if KeyComp('Helper') then Result := ptHelper;
{$ENDIF}
end;
end;
function TmwBasePasLex.Func65: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Repeat') then Result := ptRepeat;
end;
function TmwBasePasLex.Func66: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Single') then fExID := ptSingle else
if KeyComp('Type') then Result := ptType
{$IFDEF D8_NEWER}//JThurman 2004-03-23
else
if KeyComp('Unsafe') then Result := ptUnsafe
{$ENDIF}
;
end;
function TmwBasePasLex.Func69: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Default') then fExID := ptDefault else
if KeyComp('Dynamic') then fExID := ptDynamic else
if KeyComp('Message') then fExID := ptMessage;
end;
function TmwBasePasLex.Func71: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('WideChar') then fExID := ptWideChar else
if KeyComp('Stdcall') then fExID := ptStdcall else
if KeyComp('Const') then Result := ptConst;
end;
{$IFDEF D8_NEWER} //JThurman 2004-03-2003
function TmwBasePasLex.Func72: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Static') then
fExID := ptStatic;
end;
{$ENDIF}
function TmwBasePasLex.Func73: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Except') then Result := ptExcept;
end;
function TmwBasePasLex.Func75: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Write') then fExID := ptWrite;
end;
function TmwBasePasLex.Func76: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Until') then Result := ptUntil;
end;
function TmwBasePasLex.Func78: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Integer') then fExID := ptInteger
{$IFDEF D8_NEWER}
else if KeyComp('Remove') then
FExID := ptRemove
{$ENDIF}
;
end;
function TmwBasePasLex.Func79: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Finally') then Result := ptFinally
{$IFDEF D12_NEWER}
else if KeyComp('Reference') then fExID := ptReference;
{$ENDIF}
end;
function TmwBasePasLex.Func81: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Extended') then fExID := ptExtended else
if KeyComp('Stored') then fExID := ptStored else