lexer (HL), dictionnary for the special keywords use a simple sum

This commit is contained in:
Basile Burg 2016-04-10 05:14:27 +02:00
parent 02af7dee46
commit 978b13f866
1 changed files with 24 additions and 24 deletions

View File

@ -15,33 +15,33 @@ type
private private
const fWords: array [0..15] of string = const fWords: array [0..15] of string =
( (
'__PRETTY_FUNCTION__', '__VENDOR__', '', '__VERSION__', '__DATE__', '__FILE__', '', '__TIME__', '', '', '__EOF__', '__VENDOR__', '__LINE__',
'__FILE__', '__LINE__', '', '__FUNCTION__', '', '__TIMESTAMP__', '__TIME__', '', '__PRETTY_FUNCTION__', '__DATE__', '__MODULE__', '__FUNCTION__',
'__EOF__', '', '', '__MODULE__' '__TIMESTAMP__', '__VERSION__', ''
); );
const fHasEntry: array [0..15] of boolean = const fHasEntry: array [0..15] of boolean =
( (
true, true, false, true, true, true, true, false, true, false, true, true, true, false, true, false, false, true, true, true, false, true, true, true,
true, false, false, true true, true, true, false
); );
const fCoeffs: array[0..255] of Byte = const fCoeffs: array[0..255] of Byte =
( (
50, 243, 103, 74, 140, 54, 86, 48, 32, 12, 76, 146, 95, 139, 178, 149, 255, 23, 54, 252, 239, 192, 69, 42, 70, 63, 3, 89, 171, 21, 218, 140, 187, 191,
167, 77, 13, 101, 143, 16, 6, 221, 208, 221, 79, 217, 253, 102, 24, 243, 74, 12, 230, 108, 85, 152, 3, 56, 199, 164, 61, 172, 64, 225, 99, 179, 182,
208, 70, 196, 133, 33, 208, 26, 203, 72, 234, 222, 92, 240, 162, 139, 102, 174, 189, 171, 243, 108, 60, 208, 146, 6, 17, 236, 103, 127, 4, 219, 83,
174, 240, 48, 10, 173, 208, 107, 85, 176, 211, 77, 246, 56, 253, 2, 164, 85, 138, 228, 29, 243, 85, 155, 246, 32, 93, 255, 80, 135, 160, 38, 224, 3,
108, 181, 37, 35, 11, 111, 224, 51, 16, 170, 123, 245, 147, 183, 250, 15, 134, 54, 8, 27, 129, 142, 243, 201, 39, 198, 171, 242, 78, 141, 183, 57,
202, 106, 126, 199, 31, 2, 174, 221, 81, 207, 50, 170, 86, 71, 12, 51, 3, 187, 168, 138, 251, 219, 96, 186, 112, 117, 220, 164, 203, 21, 127, 101,
30, 192, 132, 159, 74, 35, 62, 90, 10, 135, 33, 23, 15, 100, 2, 69, 250, 248, 77, 41, 187, 233, 66, 20, 108, 205, 192, 246, 49, 38, 71, 106, 176, 176,
36, 120, 134, 108, 134, 54, 89, 89, 219, 86, 165, 72, 244, 130, 60, 44, 84, 253, 21, 18, 136, 165, 120, 50, 144, 62, 90, 56, 10, 0, 109, 109, 70, 108,
129, 130, 253, 90, 104, 25, 52, 103, 109, 239, 100, 16, 188, 87, 132, 201, 191, 244, 103, 237, 145, 214, 39, 227, 200, 40, 135, 49, 12, 7, 203, 37,
110, 175, 152, 181, 178, 196, 61, 52, 60, 169, 26, 52, 48, 90, 236, 244, 26, 101, 142, 4, 156, 251, 234, 144, 54, 251, 17, 82, 59, 108, 178, 60, 229,
28, 117, 65, 155, 24, 60, 216, 220, 80, 152, 202, 173, 43, 17, 48, 83, 135, 43, 72, 97, 193, 36, 253, 36, 154, 219, 246, 59, 165, 144, 136, 136, 231,
188, 251, 254, 232, 167, 196, 3, 222, 73, 169, 156, 222, 215, 217, 6, 105, 243, 222, 108, 73, 148, 208, 148, 147, 57, 9, 1, 193, 247, 251, 116, 48,
171, 130, 169, 27, 9, 147, 176, 207, 45, 43, 47, 11, 163, 215, 117, 11, 100, 72, 165, 80, 49, 86, 220, 197, 227, 71, 24, 98, 21, 132, 2, 164, 133, 186,
253, 70, 242, 169, 92, 61, 198, 236, 243, 26, 144, 220, 76, 40, 178, 158, 43, 19, 138, 166, 119, 202, 109, 124, 91, 32, 159, 155, 145, 124, 164, 19,
164, 80, 112, 61, 157, 26, 224, 53, 123, 105, 27, 170, 126, 101, 3, 65, 113, 200, 143, 191, 31, 199, 229, 240, 115, 135, 52, 181, 14, 140, 174, 12, 139,
101, 157, 109, 110, 252, 207, 0 45, 158, 171, 146, 186, 72, 34, 12, 6, 207, 151, 117
); );
class function hash(const w: string): Byte; static; {$IFNDEF DEBUG}inline;{$ENDIF} class function hash(const w: string): Byte; static; {$IFNDEF DEBUG}inline;{$ENDIF}
public public
@ -49,7 +49,7 @@ type
end; end;
(** (**
* Perfect static hash-map that detects the "straight" D2 keywords plus a few * Perfect static hash-map that detects the 'straight' D2 keywords plus a few
* exception for the library types related to immutable strings. * exception for the library types related to immutable strings.
*) *)
keywordsMap = record keywordsMap = record
@ -138,8 +138,8 @@ var
i: integer; i: integer;
begin begin
Result := 0; Result := 0;
for i := 2 to length(w) do for i := 1 to length(w) do
Result += fCoeffs[(Byte(w[i]) + (Byte(i-1) xor Byte(w[i-1]))) and $FF]; Result += fCoeffs[Byte(w[i])];
Result := Result and $F; Result := Result and $F;
end; end;
{$IFDEF DEBUG}{$POP}{$ENDIF} {$IFDEF DEBUG}{$POP}{$ENDIF}