Home
unit Reser{ved word or directive identificator };
{ Under GNU License }
{ JOAO PAULO SCHWARZ SCHULER }
{ http://www.schulers.com }
{ Turbo Pascal Source }
{ Free Pascal Source for DOS }
{ Free Pascal Source for Linux }
{ Delphi Source }
interface
Const HashingNumber = 23;
MaxOnHashLine = 10;
type STR20 = string[20];
Const RWords : array[0..HashingNumber-1,0..MaxOnHashLine-1] of str20 =
(
{00} ('CONST','OR','TYPE','','','','','','',''),
{01} ('SHL','FOR','DESTRUCTOR','INHERITED','PROPERTY','','','','',''),
{02} ('TO','OBJECT','TRY','CDECL','','','','','',''),
{03} ('VAR','ASSEMBLER','','','','','','','',''),
{04} ('AND','FORWARD','THEN','IMPLEMENTATION','LIBRARY','RAISE','','','',''),
{05} ('IF','UNTIL','PUBLISHED','STORED','','','','','',''),
{06} ('SET','CLASS','INITIALIZATION','THREADVAR','','','','','',''),
{07} ('LABEL','PROGRAM','SHR','FINALIZATION','NODEFAULT','','','','',''),
{08} ('CASE','END','DISPID','INDEX','RESIDENT','','','','',''),
{09} ('ABSOLUTE','WHILE','DO','AUTOMATED','','','','','',''),
{10} ('RECORD','PACKED','INLINE','PUBLIC','PRIVATE','AS','FAR','OVERRIDE','',''),
{11} ('OF','STRING','NOT','DEFAULT','DYNAMIC','MESSAGE','','','',''),
{12} ('FILE','REPEAT','BEGIN','','','','','','',''),
{13} ('IN','EXTERNAL','INTERFACE','EXPORTS','NAME','STDCALL','','','',''),
{14} ('GOTO','PROCEDURE','','','','','','','',''),
{15} ('DOWNTO','ARRAY','PROTECTED','','','','','','',''),
{16} ('FUNCTION','','','','','','','','',''),
{17} ('MOD','WITH','','','','','','','',''),
{18} ('IS','NEAR','','','','','','','',''),
{19} ('XOR','CONSTRUCTOR','','','','','','','',''),
{20} ('DIV','NIL','EXCEPT','','','','','','',''),
{21} ('ELSE','UNIT','USES','FINALLY','ABSTRACT','','','','',''),
{22} ('EXPORT','PASCAL','VIRTUAL','','','','','','',''));
function Key(S:string;Divisor:byte):word;
{calculates de hashing code}
{ calcula chave de acesso }
function GetHash(S:String):word;
function IsReserved(S:string):boolean;
{ checks if S is a Reserved word or a directive}
implementation
function Key(S:string;Divisor:byte):word;
{ calcula chave de acesso }
var I:integer;
SOMA:longint;
begin
SOMA:=0;
for I:=1 to length(S) do
inc(SOMA,ord(S[I]));
Key:=SOMA mod Divisor;
end;
function GetHash(S:String):word;
begin
GetHash:=Key(S,HashingNumber);
end;
function IsReserved(S:string):boolean;
{ checks if S is a Reserved word or a directive}
var HN,L:word;
C:word;
Found:boolean;
begin
L:=Length(S);
for C:=1 to L
do S[C]:=UpCase(S[C]);
HN:=GetHash(S);
C:=0;
Found:=false;
while (C<MaxOnHashLine) and (RWORDS[HN,C]<>'') and not(Found) do
begin
Found:=Found or (S=RWORDS[HN,C]);
inc(C);
end;
IsReserved:=Found;
end;
end. { of unit }