Processing String Constants

This function checks and processes string constants. It processes characters enclosed with single quotes, control characters and characters defined with the ASCII code (#code).
Function ProcessStringConstant (Var NextChar: PChar): TToken;
Var TempString: PString;
    StringPtr: Byte ;
begin
  NumericConstant.Word := GetTempBufferOffset (128);
  TempString := Ptr (DSeg, NumericConstant.Word);
  StringPtr := 1;
  Repeat
    Case NextChar^ of
      '''': begin
              Repeat
                Inc (NextChar);
                Case NextChar^ of
                  #0: begin
                        ErrorSourcePosition := NextChar;
                        Error (StringConstantExceedsLine);
                      end;
                  '''': begin
                          Inc (NextChar);
                          If NextChar^ <> '''' then Break;
                        end;
                end;
                TempString^ [StringPtr] := NextChar^;
                Inc (StringPtr);
              until False;
              Continue;
            end;
      '^': begin
             Inc (NextChar);
             If NextChar^ = #0 then
               begin
                 ErrorSourcePosition := NextChar;
                 Error (StringConstantExceedsLine);
               end;
             TempString^ [StringPtr] := Chr (Byte (UpCase (NextChar^)) xor $40);
             Inc (StringPtr);
             Inc (NextChar);
             Continue;
           end;
      '#': begin
             Inc (NextChar);
             If IsIntegerNumericConstant (NextChar) then
               begin
                 TempString^ [StringPtr] := Chr (IntegerNumericConstant);
                 Inc (StringPtr);
               end else begin
                          ErrorSourcePosition := NextChar;
                          Error (ErrorInIntegerConstant);
                        end;
           end;
      else begin
             TempString^ [StringPtr] := #0;
             TempBufferFreePositionOffset := Ofs (TempString^ [StringPtr + 1]);
             Dec (StringPtr);
             TempString^ [0] := Chr (StringPtr);
             If StringPtr = 1 then
               begin
                 TempBufferFreePositionOffset := NumericConstant.Word;
                 NumericConstant.LongInt := Byte (TempString^ [1]);
                 ConstantTypeDefRec.Ofs := Char_TypeOffset;
               end else ConstantTypeDefRec.Ofs := String_TypeOffset;
             ConstantTypeDefRec.Seg := SystemUnitSegment;
             ProcessStringConstant := Token_Constant;
             Exit;
           end;
    end;
  until False;
end;
 
 
 
© 2017 Turbo Pascal | Privacy Policy