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

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

?? calcexpress.pas

?? delphi:字符串處理函數包 很強的字符串處理包
?? PAS
字號:
//==============================================================================
// Product name: CalcExpress
// Copyright 2000-2002 AidAim Software.
// Description:
//  CalcExpress is an interpreter for quick and easy
//  evaluation of mathematical expressions.
//  It is a smart tool easy in use.
//  Supports 5 operators, parenthesis, 18 mathematical functions and
//  user-defined variables.
// Date: 06/14/2001
//==============================================================================
unit CalcExpress;

interface

{DEFINE aaCLX} // set $ after { to get CLX version

uses
  SysUtils, Classes, Math,
{$IFDEF aaCLX}
  QGraphics, QControls, QForms, QDialogs, QExtCtrls;
{$ELSE}
  Windows, Messages, Graphics, Controls, Forms, Dialogs, ExtCtrls;
{$ENDIF}

type

  TTree = record
    num: integer;
    con: string;
    l, r: pointer;
  end;

  PTree = ^TTree;

  TCalcExpress = class(TComponent)
  private
    Err: boolean;
    Bc: integer;
    PrevLex, Curlex: integer;
    Pos: integer;
    FFormula: string;
    Tree: pointer;
    FVariables: TStrings;
    FDefaultNames: boolean;
    procedure init(s: string);
    function gettree(s: string): pointer;
    function deltree(t: PTree): pointer;
    procedure Error(s: string);
    procedure SetVariables(Value: TStrings);
  public
    constructor Create(o: TComponent); override;
    destructor Destroy; override;
    function calc(args: array of extended): extended;
  published
    property Formula: string read FFormula write init;
    property Variables: TStrings read FVariables write SetVariables;

  end;

//procedure Register;
  function SimpleCalc(AText:string):Integer;

implementation

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

function SimpleCalc(AText:string):Integer;
var
  CalcTool:TCalcExpress;
begin
  CalcTool:=TCalcExpress.Create(nil);
  try
    with CalcTool do
    begin
      Formula:=AText;
      Result:=Round(calc([]));
    end;
  finally
    CalcTool.Free;
  end;
end;


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

procedure TCalcExpress.Error(s: string);
begin
  Err := True;
  raise Exception.Create(s);
end;
//*********************************************************************
constructor TCalcExpress.Create(o: TComponent);
begin
  inherited;
  Tree := nil;
  Formula := '0';
  FDefaultNames := False;
  FVariables := TStringList.Create;
end;
//*********************************************************************
destructor TCalcExpress.Destroy;
begin
  DelTree(Tree);
  FVariables.Free;
  inherited;
end;

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

function TCalcExpress.GetTree(s: string): pointer;
  //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: PTree;
  n, op: integer;
  c: string;
  //****************************************************************
  function newnode: PTree;
  begin
    Result := allocmem(sizeof(TTree));
    Result^.l := nil;
    Result^.r := nil;
  end;

  function getsingleop: pointer;
  var 
    op, bracket: integer;
    opc: string;
    l, r, res: PTree;
  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 := newnode; 
          l^.num := op; 
          l^.con := opc;
        end 
        else
        begin
          //Function
          getlex(s, n, c);
          if n <> 1 then Error('');
          inc(bc);
          l := newnode;
          l^.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 := newnode; 
        r^.num := n; 
        r^.con := c;
        res := newnode; 
        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
      DelTree(l);
      Result := nil;
    end;
  end;
  //****************************************************************
  function getop: pointer;
  var 
    op: integer;
    l, r, res: PTree;
  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 := allocmem(sizeof(TTree));
      res^.l := l; 
      res^.r := r; 
      res^.num := op;
      l := res;
    end;
    // Unary minus
    if neg then
    begin
      res := allocmem(sizeof(TTree));
      res^.l := l; 
      res^.r := nil; 
      res^.num := 9;
      l := res;
    end;
    Result := l;
  end;

  //****************************************************************
begin
  l := 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('');
      op := n;
      r := getop;
      res := allocmem(sizeof(TTree));
      res^.l := l; 
      res^.r := r; 
      res^.num := op;
      l := res;
    end;
    Result := l;
  except
    DelTree(l);
    Result := nil;
  end;
end;

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

procedure TCalcExpress.init(s: string);
begin
  deltree(tree);
  Err := False;
  FFormula := LowerCase(s);
  Prevlex := 0;  
  Curlex := 0;  
  Pos := 1;  
  bc := 0;
  Tree := GetTree(Lowercase(s));
  if (bc <> 0) or Err then
  begin
    ShowMessage('Error in formula.');
    Tree := DelTree(Tree);
  end;
end;

//Tree deletion

function TCalcExpress.deltree(t: PTree): pointer;
begin
  Result := nil;
  if t = nil then exit;
  if t^.l <> nil then Deltree(t^.l);
  if t^.r <> nil then Deltree(t^.r);
  freemem(t);
end;

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


end.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美激情中文字幕一区二区| 蜜桃91丨九色丨蝌蚪91桃色| 亚洲国产精品v| 久久久av毛片精品| 1024成人网| 亚洲第一主播视频| 国产精品69毛片高清亚洲| 国产精品亚洲成人| 欧美视频一区二| 99久久精品免费精品国产| 欧美精品一二三四| 亚洲一区中文在线| 色婷婷综合五月| 一区二区高清视频在线观看| av一区二区久久| 亚洲精品写真福利| 日本高清视频一区二区| 亚洲精品视频一区| 欧美区在线观看| 麻豆一区二区三| 久久在线观看免费| 婷婷夜色潮精品综合在线| 在线亚洲高清视频| 免费观看在线色综合| 精品久久久久久久一区二区蜜臀| 久久精品国产久精国产爱| av亚洲精华国产精华精华| 91麻豆精品国产自产在线| 午夜精品福利一区二区三区av| bt欧美亚洲午夜电影天堂| 欧美精品一区二区在线播放| 亚洲va韩国va欧美va精品| 欧美日韩一区二区三区在线| 亚洲欧美日韩国产综合在线| 成人精品一区二区三区四区| 国产欧美日本一区视频| 国产一区二区美女| 国产精品亲子伦对白| 成人黄色大片在线观看| 中文字幕高清一区| 色哟哟一区二区三区| 欧美一区二区三区电影| 国产麻豆91精品| 婷婷综合另类小说色区| 亚洲图片激情小说| 日韩一级黄色大片| 91啪九色porn原创视频在线观看| 欧美人伦禁忌dvd放荡欲情| 久久精品国产在热久久| 玉米视频成人免费看| 日韩亚洲欧美中文三级| 久久精品国产一区二区三| 欧美电影免费观看完整版| 日韩av电影免费观看高清完整版 | 国产91富婆露脸刺激对白| www激情久久| 床上的激情91.| 亚洲综合久久久久| 91精品国产美女浴室洗澡无遮挡| 一区二区三区精品久久久| 555www色欧美视频| 成人性视频网站| 午夜视频一区二区| 国产喂奶挤奶一区二区三区| 一本久久精品一区二区| 日韩精品亚洲专区| 国产精品久久久久毛片软件| 欧美日本一区二区三区四区 | 99国产麻豆精品| 天堂va蜜桃一区二区三区| 国产区在线观看成人精品| 欧美视频完全免费看| 国产69精品一区二区亚洲孕妇| 亚洲精品老司机| 国产精品久久看| 欧美电影免费观看高清完整版在| 在线视频欧美精品| 成人精品免费网站| 狠狠色丁香久久婷婷综| 悠悠色在线精品| 亚洲日本在线a| 国产精品区一区二区三| 久久久影院官网| 久久精品亚洲乱码伦伦中文| 日韩免费一区二区| 欧美一级搡bbbb搡bbbb| 欧美一级二级在线观看| 日韩亚洲欧美在线观看| 日韩免费观看高清完整版在线观看| 欧美吻胸吃奶大尺度电影| 在线观看成人免费视频| 在线观看一区二区视频| 欧美日韩在线播放一区| 91色综合久久久久婷婷| 欧美在线看片a免费观看| 成人中文字幕电影| 99精品热视频| 欧美日韩在线播放一区| 日韩一卡二卡三卡四卡| 欧日韩精品视频| 美国十次综合导航| 国产成人精品1024| av激情亚洲男人天堂| 91网站在线播放| 日韩一区二区在线看片| 久久久久久久久久久久久女国产乱| 久久久亚洲高清| 亚洲乱码中文字幕综合| 日本v片在线高清不卡在线观看| 另类综合日韩欧美亚洲| 99精品视频在线播放观看| 欧美日韩中文国产| 亚洲欧洲精品一区二区精品久久久| 一区二区三区四区高清精品免费观看| 亚洲国产成人av网| 北岛玲一区二区三区四区| 91精品一区二区三区在线观看| 中文字幕欧美激情一区| 免费人成精品欧美精品| 欧美中文字幕不卡| 亚洲欧美怡红院| 国产福利一区二区三区| 欧美成人在线直播| 亚洲成人一二三| 色婷婷av一区二区三区软件 | 美女精品一区二区| 在线欧美一区二区| 亚洲日本护士毛茸茸| 成人一级片网址| 中文一区一区三区高中清不卡| 奇米一区二区三区| 欧美一区二区久久| 日韩电影免费在线观看网站| 欧美日韩激情一区| 日韩高清一级片| 日韩午夜小视频| 国产精品66部| 国产精品三级电影| 色婷婷狠狠综合| 午夜精品国产更新| 91精品国产综合久久久久久久 | 日韩色在线观看| 激情欧美一区二区三区在线观看| 日韩一区二区精品在线观看| 捆绑紧缚一区二区三区视频| 久久亚洲综合色一区二区三区 | 久久精品无码一区二区三区| 懂色av一区二区三区蜜臀 | 亚洲欧洲美洲综合色网| 国产一区二区三区四区在线观看 | 韩国精品主播一区二区在线观看| 精品国产百合女同互慰| 成人美女视频在线观看| 日韩成人免费在线| 成人欧美一区二区三区黑人麻豆 | 日韩成人午夜精品| 国产精品久久久久久久久果冻传媒| 色婷婷综合久久久久中文一区二区| 一区二区三区四区不卡在线| 欧美精品123区| 91成人国产精品| 国产成人av福利| 日本vs亚洲vs韩国一区三区| 欧美激情一区不卡| 久久色在线视频| 欧美一级搡bbbb搡bbbb| 欧洲精品在线观看| 不卡的av电影| 国产成人综合自拍| 国产盗摄视频一区二区三区| 久久精品国产99国产精品| 亚洲va天堂va国产va久| 一区二区三区高清| 亚洲日本在线天堂| 一区在线中文字幕| 中文字幕一区视频| 亚洲国产精品高清| 国产精品无人区| 久久亚洲精品国产精品紫薇| 日韩视频一区二区三区在线播放| 欧美区视频在线观看| 6080亚洲精品一区二区| 欧美一区二区三区系列电影| 欧美亚洲国产bt| 宅男在线国产精品| 日韩欧美中文字幕一区| 欧美电影免费提供在线观看| 国产日韩精品视频一区| 亚洲欧美综合在线精品| 香蕉成人啪国产精品视频综合网| 亚洲一区二区三区四区在线免费观看| 亚洲一区二区三区美女| 另类专区欧美蜜桃臀第一页| 国产91对白在线观看九色| 91麻豆国产在线观看| 日韩一区二区免费电影| 国产精品久久久久9999吃药| 亚洲二区视频在线| 国产精品一色哟哟哟| 欧美三级日韩在线|