Press enter to see results or esc to cancel.

Checking For Special Words

Turbo Pascal uses few special words as directives for special functions: ABSOLUTE, ASSEMBLER, EXTERNAL, FAR, FORWARD, INTERRUPT, NEAR, PRIVATE, PUBLIC, VIRTUAL and System as unit name.

Type TSpecialWord = Record
                      Text: String [9];
                      Hash: Byte;
                    end;

  _ABSOLUTE: TSpecialWord = (Text: 'ABSOLUTE'; Hash: $AE);
  _ASSEMBLER: TSpecialWord = (Text: 'ASSEMBLER'; Hash: $2A);
  _EXTERNAL: TSpecialWord = (Text: 'EXTERNAL'; Hash: $B6);
  _FAR: TSpecialWord = (Text: 'FAR'; Hash: $AC);
  _FORWARD: TSpecialWord = (Text: 'FORWARD'; Hash: $1C);
  _INTERRUPT: TSpecialWord = (Text: 'INTERRUPT'; Hash: $88);
  _NEAR: TSpecialWord = (Text: 'NEAR'; Hash: $44);
  _PRIVATE: TSpecialWord = (Text: 'PRIVATE'; Hash: $28);
  _PUBLIC: TSpecialWord = (Text: 'PUBLIC'; Hash: $72);
  _VIRTUAL: TSpecialWord = (Text: 'VIRTUAL'; Hash: $40);
  _System: TSpecialWord = (Text: 'System'; Hash: $BE);

This function checks if special directive is present.

Procedure CheckIfDirecive (Directive: TSpecialWord; NewToken: TToken);
begin
  If CompareIdentifierToWord (Directive) then Token := NewToken;
end;

This function actually compares current identifier with each of special words. To speed up the search the hash value is compared first, then IdentifiersEqual is called.

Function CompareIdentifierToWord (SpecialWord: TSpecialWord): Boolean;
Var TempPtr: PString;
begin
  CompareIdentifierToWord := False;
  If Token <> Token_Identifier then Exit;
  If CurrentIdentifierHash <> SpecialWord.Hash then Exit;
  TempPtr := @SpecialWord.Text;
  If not IdentifiersEqual (@CurrentIdentifier, TempPtr) then Exit;
  CompareIdentifierToWord := True;
end;