Processing Integer Constants

These two functions check and process decimal and hexadecimal integer constants. The value is stored in the IntegerNumericConstant variable.
Function IsIntegerNumericConstant (Var CharacterPointer: PChar): Boolean;
begin
  If CharacterPointer [0] = '$' then
    begin
      Inc (CharacterPointer);
      IsIntegerNumericConstant := IsHexConstant (CharacterPointer);
      Exit;
    end;
  IntegerNumericConstant := 0;
  IsIntegerNumericConstant := False;
  While CharacterPointer [0] in DecChars do
    begin
      If IntegerNumericConstantRec.WordH and $F000 <> 0 then
        begin
          IsIntegerNumericConstant := False;
          Exit;
        end;
      IntegerNumericConstant := IntegerNumericConstant * 10 + Ord (CharacterPointer [0]) - Ord ('0');;
      If IntegerNumericConstantRec.WordH and $8000 <> 0 then    { BUG in TPC ?                 }
        begin                                                   { -2147483648 causes error !!! }
          IsIntegerNumericConstant := False;
          Exit;
        end;
      Inc (CharacterPointer);
      IsIntegerNumericConstant := True;
    end;
end;
Function IsHexConstant (Var HexCharPointer: PChar): Boolean;
Var Digit: Byte;
    Chr: Char;
begin
  IsHexConstant := False;
  IntegerNumericConstant := 0;
  Chr := UpCase (HexCharPointer [0]);
  While Chr in HexChars do
    begin
      Digit := Byte (Chr) - Ord ('0');
      If Digit > 9 then Digit := Digit - (Ord ('A') - Ord ('0') - 10);
      If IntegerNumericConstantRec.WordH and $F000 <> 0 then
        begin
          IsHexConstant := False;
          Exit;
        end;
      IntegerNumericConstant := IntegerNumericConstant shl 4;
      IntegerNumericConstantRec.WordL := IntegerNumericConstantRec.WordL or Digit;
      Inc (HexCharPointer);
      Chr := UpCase (HexCharPointer [0]);
      IsHexConstant := True;
    end;
end;
 
 
 
© 2017 Turbo Pascal | Privacy Policy