Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.pascal.borland    |    Borland Pascal was actually pretty neat    |    2,978 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 2,043 of 2,978    |
|    Heinrich Wolf to All    |
|    Re: Calculate the string statement (1/11    |
|    11 Feb 06 16:59:43    |
   
   From: invalid@invalid.invalid   
      
   Hi,   
      
   long years ago I made a parser for math functions with the argument x   
   and parameters like a, b, ...   
   It has the abilities to differentiate the function and calculate values from   
   given x.   
   If you wonder about some types I declared, then you should know, that I   
   ported it   
   from schtac pascal on a commodore 4032 to turbo pascal 5.   
   However it is german language.   
      
   Here is the main module diff.pas :   
   =======================   
   program diff;   
      
   uses crt,   
    zusatz,   
    Strings;   
      
   const zlen = 16;   
   type t = (arg,verkn,funkt,sconst,zconst);   
    p = ^op;   
    op = record   
    case typ : t of   
    arg :();   
    verkn :(vkn :char;   
    op1,op2:p;   
    );   
    funkt :(fkt :string;   
    opr :p;   
    );   
    sconst:(scn :string);   
    zconst:(zcn :real);   
    end;   
    cp = ^cl;   
    cl = record   
    scn : string;   
    zcn : real;   
    nxt : cp;   
    end;   
      
   var fkt,dfkt : p;   
    clist : cp;   
    diffanz,i : integer;   
    x,f : real;   
    erfolg : boolean;   
    ch : char;   
      
   function sign(x:real):integer;   
    begin   
    if x<>0 then   
    if x>0 then   
    sign:=+1   
    else   
    sign:=-1   
    else   
    sign:=0;   
    end;   
      
   procedure delbl(var s:string);   
    var i : integer;   
    begin   
    i:=1;   
    while i<=length(s) do   
    begin   
    if s[i]=' ' then   
    s:=copy(s,1,pred(i))+copy(s,succ(i),$ff)   
    else   
    inc(i);   
    end;   
    end; (* delbl *)   
      
   procedure strreal(zk:string; var z:real; var erfolg:boolean);   
    var code : integer;   
    begin   
    delbl(zk);   
    val(zk,z,code);   
    erfolg:=code=0;   
    end; (* strreal *)   
      
   procedure realstr(z:real; var zk:string);   
    var ma : real;   
    ex : integer;   
    exk : string;   
    sm : integer;   
    nm : integer;   
    i,ic : integer;   
    d,e : integer;   
    r : real;   
      
    function ziff(i:integer):char;   
    begin   
    ziff:=chr(i+ord('0'));   
    end; (* ziff *)   
      
    begin (* realstr *)   
    nm:=zlen-6;   
    ma:=abs(z);   
    sm:=0;   
    if z<0 then sm:=1;   
    ex:=0;   
    zk:='';   
    if ma>0 then   
    begin   
    r:=5;   
    for i:=1 to nm do   
    r:=r/10;   
    if ma>=10 then   
    while ma>=10 do   
    begin   
    ma:=ma/10;   
    ex:=ex+1;   
    end   
    else   
    while ma<1 do   
    begin   
    ma:=ma*10;   
    ex:=ex-1;   
    end;   
    ma:=ma+r;   
    if ma>=10 then   
    begin   
    ma:=ma/10;   
    ex:=ex+1;   
    end;   
    end;   
    for i:=1 to nm do   
    begin   
    ic:=trunc(ma);   
    zk:=zk+ziff(ic);   
    ma:=(ma-ic)*10;   
    end;   
    ex:=ex-nm+1;   
    ic:=nm;   
    while (ic>1) and (zk[ic]='0') do   
    begin   
    dec(ic);   
    zk:=copy(zk,1,ic);   
    ex:=ex+1;   
    end;   
    if z=0 then   
    ex:=0;   
    if sm=1 then   
    begin   
    zk:='-'+zk;   
    ic:=ic+1;   
    end;   
    e:=2;   
    if ic-sm>1 then e:=3;   
    if nm-ic
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca