亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? calcexpress.pas

?? CalcExpress is an interpreter for quick and easy evaluation of mathematical expressions. It is a sm
?? PAS
字號:
unit CalcExpress;

{%File 'CalcExpress.bdsproj'}

interface

uses
  Windows,
  Classes,
  StrUtils,
  Math,
  Dialogs,
  SysUtils;

const DecimalSeparator = '.';

type
  TTree = class;



  TCalcExpress = class (TComponent)
  private
    FArgs: array of extended;
    Err: boolean;
    Bc: integer;
    PrevLex, Curlex: integer;
    Pos: integer;
    FFormula: string;
    FVariables: TStrings;
    FDefaultNames: boolean;

  private
    function SetFormula(s: string): TTree;
    function gettree(s: string): TTree;
    procedure Error(s: string);
    procedure SetVariables(Value: TStrings);
    function InternalCalc(t: TTREE): extended;

  public
    constructor Create(o: TComponent); override;
    function calc(args: array of extended): extended;
  published
    property Formula: string read FFormula write FFormula;
    property Variables: TStrings read FVariables write SetVariables;
  end;

  TTree = class
  public
    num:    Integer;
    con:    String;
    l, r:   TTree;
   constructor Create;
  end;

procedure Register;

implementation


function TCalcExpress.SetFormula(s: string): TTree;
begin
  Err := False;
  FFormula := s.ToLower;
  Prevlex := 0;
  Curlex := 0;
  Pos := 1;
  bc := 0;
  Result := GetTree(FFormula.ToLower);
  if (bc <> 0) or Err then
  begin
    ShowMessage('Error in formula.');
  end;
end;

//***************************************************************

function TCalcExpress.GetTree(s: string): TTree;
  //Get number from string
  function getnumber(s: string): string;
  begin
    Result := '';
    try
      //Begin
      while (pos <= length(s)) and (s[pos] in ['0'..'9']) do
      begin
        Result := Result + s[pos];
        inc(pos);
      end;
      if pos > length(s) then exit;
      if s[pos] = DecimalSeparator then
      begin
        //Fraction part
        Result := Result + DecimalSeparator;
        inc(pos);
        if (pos > length(s)) or not (s[pos] in ['0'..'9']) then Error('Wrong number.');
        while (pos <= length(s)) and
          (s[pos] in ['0'..'9']) do
        begin
          Result := Result + s[pos];
          inc(pos);
        end;
      end;
      if pos > length(s) then exit;
      //Power
      if (s[pos] <> 'e') and (s[pos] <> 'E') then exit;
      Result := Result + s[pos];
      inc(pos);
      if pos > length(s) then Error('Wrong number.');
      if s[pos] in ['-', '+'] then
      begin
        Result := Result + s[pos];
        inc(pos);
      end;
      if (pos > length(s)) or not (s[pos] in ['0'..'9']) then Error('Wrong number.');
      while (pos <= length(s)) and
        (s[pos] in ['0'..'9']) do
      begin
        Result := Result + s[pos];
        inc(pos);
      end;
    except
    end;
  end;
  //Read lexem from string
  procedure getlex(s: string; var num: integer; var con: string);
  begin
    con := '';
    //skip spaces
    while (pos <= length(s)) and (s[pos] = ' ') do inc(pos);
    if pos > length(s) then
    begin 
      num := 0;  
      exit; 
    end;

    case s[pos] of
      '(': num := 1;
      ')': num := 2;
      '+': num := 3;
      '-': 
      begin
        num := 4;
        if (pos < length(s)) and (s[pos + 1] in ['1'..'9', '0']) and (curlex in [0,1]) then
        begin
          inc(pos);
          con := '-' + getnumber(s);
          dec(pos);
          num := 7;
        end;
      end;
      '*': num := 5;
      '/': num := 6;
      '^': num := 31;
      'a'..'z', 'A'..'Z', '_':
      begin
        while (pos <= length(s)) and
          (s[pos] in ['a'..'z', 'A'..'Z', '_', '1'..'9', '0']) do
        begin
          con := con + s[pos];
          inc(pos);
        end;
        dec(pos);
        num := 8;
        if con = 'cos' then num := 10;
        if con = 'sin' then num := 11;
        if con = 'tg' then num := 12;
        if con = 'ctg' then num := 13;
        if con = 'abs' then num := 14;
        if (con = 'sgn') or (con = 'sign') then num := 15;
        if con = 'sqrt' then num := 16;
        if con = 'ln' then num := 17;
        if con = 'exp' then num := 18;
        if con = 'arcsin' then num := 19;
        if con = 'arccos' then num := 20;
        if (con = 'arctg') or (con = 'arctan') then num := 21;
        if con = 'arcctg' then num := 22;
        if (con = 'sh') or (con = 'sinh') then num := 23;
        if (con = 'ch') or (con = 'cosh') then num := 24;
        if (con = 'th') or (con = 'tanh') then num := 25;
        if (con = 'cth') or (con = 'coth') then num := 26;
        if (con = 'heaviside') or (con = 'h') then num := 27;
        if num = 8 then  con := IntToStr(FVariables.IndexOf(con));
      end;
      '1'..'9', '0':
      begin
        con := getnumber(s);
        dec(pos);
        num := 7;
      end;
    end;
    inc(pos);
    PrevLex := CurLex;
    CurLex := num;
  end;

  //****************************************************************
var
  neg: boolean;
  l, r, res: TTree;
  n, op: integer;
  c: string;
  //****************************************************************

  function getsingleop: TTree;
  var
    op, bracket: integer;
    opc: string;
    l, r, res: TTree;
  begin
    l := nil;
    try
      if n = 1 then
      begin
        inc(bc);
        l := gettree(s);
      end
      else
      begin
        // First operand
        if not (n in [7,8,10..30]) then Error('');
        op := n;
        opc := c;
        if n in [7,8] then
        begin
          // Number or variable
          l := TTree.Create;
          l.num := op;
          l.con := opc;
        end
        else
        begin
          //Function
          getlex(s, n, c);
          if n <> 1 then Error('');
          inc(bc);
          l := gettree(s);
          l.num := op;
          l.con := opc;
        end;
      end;
      //Operation symbol
      getlex(s, n, c);
      //Power symbol
      while n = 31 do
        begin
          getlex(s, n, c);
        bracket := 0;
        if n = 1 then
        begin
          bracket := 1;
          getlex(s, n, c);
        end;
        if (n <> 7) and (n <> 8) then Error('');
        r := TTree.Create;
        r.num := n;
        r.con := c;
        res := TTree.Create;
        res.l := l;
        res.r := r;
        res.num := 31;
        l := res;
        if bracket = 1 then
        begin
          getlex(s, n, c);
          if n <> 2 then Error('');
        end;
        getlex(s, n, c);
      end;
      Result := l;
    except
      Result := nil;
    end;
  end;
  //****************************************************************
  function getop: TTree;
  var
    op: integer;
    l, r, res: TTree;
  begin
    neg := False;
    getlex(s, n, c);
    // Unary - or +
    if prevlex in [0,1] then
    begin
      if n = 4 then
      begin
        neg := True;
        getlex(s, n, c);
      end;
      if n = 3 then getlex(s, n, c);
    end;
    l := getsingleop;
    // 2nd operand **************
    while n in [5,6] do
    begin
      op := n;
      getlex(s, n, c);
      r := getsingleop;
      res := TTree.Create;
      res.l := l;
      res.r := r;
      res.num := op;
      l := res;
    end;
    // Unary minus
    if neg then
    begin
      res := TTree.Create;
      res.l := l;
      res.r := nil;
      res.num := 9;
      l := res;
    end;
    Result := l;
  end;

  //****************************************************************
begin
  Result := nil;
  try
    l := getop;
    while True do
    begin
      if n in [0,2] then
      begin
        if n = 2 then dec(bc);
        Result := l;
        exit;
      end;
      if not (n in [3,4]) then Error(n.ToString);
      op := n;
      r := getop;
      res := TTree.Create;
      res.l := l;
      res.r := r;
      res.num := op;
      l := res;
    end;
    Result := l;
  except
    Result := nil;
  end;
end;

//******************************************************************

function TCalcExpress.InternalCalc(t: TTREE): extended;
var
    r: extended;
begin
    Result := 0;
    if (t <> nil) then
    case t.num of
      3: Result := InternalCalc(t.l) + InternalCalc(t.r);
      4: Result := InternalCalc(t.l) - InternalCalc(t.r);
      5: Result := InternalCalc(t.l) * InternalCalc(t.r);
      6: Result := InternalCalc(t.l) / InternalCalc(t.r);
      7: Result := strtofloat(t.con);
      8: Result := FArgs[StrToInt(t.con)];
      9: Result := -InternalCalc(t.l);
      10: Result := cos(InternalCalc(t.l));
      11: Result := sin(InternalCalc(t.l));
      12: Result := tan(InternalCalc(t.l));
      13: Result := 1 / tan(InternalCalc(t.l));
      14: Result := abs(InternalCalc(t.l));
      15:
      begin
        r := InternalCalc(t.l);
        if r < 0 then Result := -1
        else if r > 0 then Result := 1
        else
          Result := 0;
      end;
      16: Result := sqrt(InternalCalc(t.l));
      17: Result := ln(InternalCalc(t.l));
      18: Result := exp(InternalCalc(t.l));
      19: Result := arcsin(InternalCalc(t.l));
      20: Result := arccos(InternalCalc(t.l));
      21: Result := arctan(InternalCalc(t.l));
      22: Result := pi / 2 - arctan(InternalCalc(t.l));
      23:
      begin
        r := InternalCalc(t.l);
        Result := (exp(r) - exp(-r)) / 2;
      end;
      24:
      begin
        r := InternalCalc(t.l);
        Result := (exp(r) + exp(-r)) / 2;
      end;
      25:
      begin
        r := InternalCalc(t.l);
        Result := (exp(r) - exp(-r)) / (exp(r) + exp(-r));
      end;
      26:
      begin
        r := InternalCalc(t.l);
        Result := (exp(r) + exp(-r)) / (exp(r) - exp(-r));
      end;
      27:
      begin
        r := InternalCalc(t.l);
        if r >= 0 then Result := 1
        else
          Result := 0;
      end;
      31: Result := power(InternalCalc(t.l), InternalCalc(t.r));
    end;

end; // InternalCalc


//*********************************************************************
constructor TCalcExpress.Create(o: TComponent);
begin
  inherited;
  Formula := '0';
  FDefaultNames := False;
  FVariables := TStringList.Create;
end;



//*********************************************************************
function TCalcExpress.calc(args: array of extended): extended;
var ExprTree: TTree;
begin
  FArgs := args;
  ExprTree := SetFormula(FFormula);
  if (ExprTree = nil) then
   begin
    Result := 0;
    ShowMessage('Error in formula.');
   end
  else
   calc := InternalCalc(ExprTree);
end;



//Tree deletion

//****************************************************************
procedure TCalcExpress.SetVariables(Value: TStrings);
begin
  FVariables.Clear;
  FVariables.Assign(Value);
end;



procedure TCalcExpress.Error(s: string);
begin
  Err := True;
  raise Exception.Create(s);
end;


constructor TTree.Create;
begin
  inherited;
  num := 0;
  l := nil;
  r := nil;
end;



procedure Register;
begin
  RegisterComponents('Samples', [TCalcExpress]);
end;

end.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩久久久| 国产精品久久久久久一区二区三区| 欧美大片在线观看一区| 国产精品传媒在线| 天天操天天干天天综合网| 成人午夜av影视| 精品国产一区二区在线观看| 夜夜嗨av一区二区三区| 风间由美性色一区二区三区| 538prom精品视频线放| 亚洲你懂的在线视频| 国产很黄免费观看久久| 在线综合亚洲欧美在线视频| 亚洲人吸女人奶水| 国产成人免费网站| 亚洲精品一线二线三线无人区| 亚洲第一综合色| 一本到不卡精品视频在线观看| 国产午夜精品一区二区三区嫩草| 蜜桃一区二区三区在线观看| 欧美日韩精品福利| 亚洲综合色丁香婷婷六月图片| 91一区二区在线观看| ...av二区三区久久精品| 国产高清久久久久| 国产欧美精品日韩区二区麻豆天美| 美女脱光内衣内裤视频久久影院| 欧美精品丝袜久久久中文字幕| 亚洲激情五月婷婷| 在线观看日产精品| 一区二区三区四区在线播放| 色老综合老女人久久久| 亚洲免费av在线| 欧美性生交片4| 午夜精品久久久久久久| 欧美日韩在线免费视频| 婷婷国产在线综合| 91精品国产色综合久久| 麻豆91精品视频| 欧美成人综合网站| 国产精品一二三四| 成人免费小视频| 一本一道波多野结衣一区二区| 亚洲手机成人高清视频| 在线亚洲免费视频| 日韩av成人高清| 欧美成人video| 国产91丝袜在线播放九色| 国产精品国产三级国产| 在线观看日韩精品| 免费在线观看不卡| 日本一区二区免费在线观看视频| 成人免费视频一区| 亚洲一区二区三区国产| 日韩精品一区二区三区中文不卡| 国产69精品一区二区亚洲孕妇| 国产精品久久久久久福利一牛影视 | 欧美日韩国产片| 日韩国产精品久久久| 久久久不卡网国产精品二区 | 精品一区二区三区久久久| 欧美精品一区二区久久婷婷| 成人少妇影院yyyy| 舔着乳尖日韩一区| 久久久久久97三级| 欧美影视一区二区三区| 激情文学综合网| 亚洲欧美成人一区二区三区| 日韩一卡二卡三卡国产欧美| 国产盗摄精品一区二区三区在线| 亚洲欧美韩国综合色| 亚洲精品一区二区三区精华液| 91免费精品国自产拍在线不卡| 婷婷中文字幕一区三区| 中文字幕精品综合| 91精品国产入口在线| 99久久精品免费看| 国产在线一区观看| 亚洲国产一区视频| 国产精品久久久久久久久图文区| 欧美一区二区精美| 91行情网站电视在线观看高清版| 久88久久88久久久| 亚洲国产成人av网| 国产精品久久网站| 欧美大片在线观看一区| 欧美中文字幕亚洲一区二区va在线| 国产毛片精品国产一区二区三区| 亚洲综合av网| 国产精品国产三级国产普通话三级| 日韩免费观看高清完整版| 欧美主播一区二区三区| 99久久精品一区二区| 国产成人精品免费| 精品一区二区三区在线播放| 亚洲线精品一区二区三区| 国产精品伦一区| 2022国产精品视频| 日韩久久免费av| 欧美电影在线免费观看| 欧美视频在线不卡| 色婷婷综合久久久| av在线不卡网| 成人免费高清视频| 成人综合在线网站| 国产成人在线色| 国产黄人亚洲片| 国产成人午夜视频| 高清不卡一二三区| 国产成人一级电影| 丁香桃色午夜亚洲一区二区三区| 经典三级一区二区| 久久精品99国产精品| 美女看a上一区| 久久99久久精品| 国产精品亚洲专一区二区三区| 另类小说综合欧美亚洲| 久久精品国产亚洲a| 久久91精品国产91久久小草| 国产综合色在线| 国产精品一级在线| 成人激情电影免费在线观看| 成人av电影在线观看| 91社区在线播放| 色呦呦国产精品| 欧美日韩一级视频| 4438亚洲最大| 精品91自产拍在线观看一区| 国产色婷婷亚洲99精品小说| 欧美极品aⅴ影院| 亚洲人123区| 亚洲va国产va欧美va观看| 蜜桃一区二区三区在线| 国产精品羞羞答答xxdd| 成人av电影在线网| 欧美日韩你懂得| 日韩欧美123| 中文字幕在线一区免费| 一区二区三区欧美在线观看| 婷婷中文字幕一区三区| 国产一区二区在线免费观看| 成人午夜电影小说| 欧美人xxxx| 国产日韩综合av| 亚洲乱码国产乱码精品精98午夜| 亚洲一区二区三区四区不卡| 日产欧产美韩系列久久99| 国产精品香蕉一区二区三区| 91色视频在线| 欧美一区二区三区视频免费| 国产日韩成人精品| 亚洲影院理伦片| 极品尤物av久久免费看| 一本一道久久a久久精品| 91精品国产免费| 中国色在线观看另类| 欧美精选午夜久久久乱码6080| 日韩女优av电影| 有码一区二区三区| 国产精品99久久久久久久女警| 欧美亚男人的天堂| 国产亚洲综合在线| 亚洲r级在线视频| av在线播放成人| 久久综合久久鬼色| 亚洲福中文字幕伊人影院| 国产盗摄一区二区三区| 制服丝袜亚洲精品中文字幕| 中文字幕精品—区二区四季| 日本欧洲一区二区| 日本伦理一区二区| 亚洲午夜精品网| 国产精品亚洲成人| 日韩三区在线观看| 一区二区三区加勒比av| 国产白丝网站精品污在线入口| 欧美精品久久一区| 亚洲天堂免费看| 粉嫩绯色av一区二区在线观看| 在线成人av网站| 夜夜嗨av一区二区三区网页 | 日本一不卡视频| 色激情天天射综合网| 国产清纯美女被跳蛋高潮一区二区久久w | 久久久久久久久久久久久女国产乱| 亚洲精品国产精品乱码不99| 成人性生交大合| 久久伊99综合婷婷久久伊| 免费在线成人网| 欧美电影免费观看高清完整版在线观看| 一区二区三区日韩| 色欧美乱欧美15图片| 亚洲视频电影在线| 成人激情免费电影网址| 国产欧美一区在线| 成人精品高清在线| 国产精品美女久久久久久| 国产91在线观看丝袜| 中文幕一区二区三区久久蜜桃| 国产精品一区专区|