
unit TANK;

interface

uses
  CYPHER, STRINGS;

function  _CALCSTRING (TEKST : string) : string;

implementation

function  _CALCSTRING (TEKST : string) : string;
  var
    TEMP      : string;
    C, D      : byte;
    BRACKETS  : integer;
    PLUS      : boolean;
  begin
    if pos ('$', TEKST) = 0 then begin
      _CALCSTRING:= ANYTHING (TEKST);
      exit;
    end;
    TEMP:= '';
    C:= 1;
    repeat
      case TEKST[C] of
        '$': begin
          D:= C;
          case TEKST[C-1] of
            'R', 'r': begin
              insert ('{', TEKST, C-3);
              inc (C, 1);
            end;
            'D', 'd': begin
              insert ('{', TEKST, C-3);
              inc (C, 1);
            end;
            'T', 't': begin
              case (TEKST[C-2]) of
                'H', 'h': begin
                  insert ('{', TEKST, C-5);
                  inc (C, 1);
                end;
                'F', 'f': begin
                  insert ('{', TEKST, C-4);
                  inc (C, 1);
                end;
              end;
            end;
          end;
(*          PLUS:= false;*)
          repeat
            inc (C, 1);
(*            if TEKST[C] = '+' then
              PLUS:= true;
            if TEKST[C] = '(' then
              PLUS:= false;
            *)
          until ((TEKST[C]=')') (*and (not PLUS)*)) or (C > length (TEKST));
          insert ('}', TEKST, C+1);
          C:= D+1;
        end;
       end;
       C:= C + 1;
     until C>length(TEKST);
    while (pos ('}}', TEKST) > 0) do begin
      delete (TEKST, pos('}}', TEKST), 1);
    end;
    _CALCSTRING:= CALCSTRING (TEKST);
  end;

begin
end.