home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / doit.zip / DO.PAS < prev   
Pascal/Delphi Source File  |  1989-09-24  |  3KB  |  89 lines

  1. Program DoDo;
  2.  
  3. (*
  4. ┌───────────────────────────────────────────────────────────────────────────┐
  5. │                                DO.PAS                                     │
  6. ├───────────────────────────────────────────────────────────────────────────┤
  7. │   Versión             : 1.5                                               │
  8. │   Computadora         : IBM-PC o compatible                               │
  9. │   Lenguaje            : Turbo Pascal 5.5                                  │
  10. │   Autor               : Bernardo Zamora Etcharren                         │
  11. └───────────────────────────────────────────────────────────────────────────┘
  12. *)
  13.  
  14.  
  15. Uses
  16.   do_type,
  17.   do_rpn,
  18.   do_eval;
  19.  
  20. var
  21.   result,             { result of the evaluation                   }
  22.   x_value : real;     { value of the X evaluating                  }
  23.   rpn     : rpn_type; { record to pass/get info from/to procedures }
  24.   i       : integer;
  25.  
  26.  
  27. Procedure ChecaParametros;
  28. var
  29.   i : integer;
  30. begin
  31.   if ParamCount=0 then begin
  32.     writeln('Usage : DO operations    <- perform the "operations"');
  33.     writeln('        DO ?             <- display help screen');
  34.     halt(1);
  35.   end else if (ParamCount=1) and (ParamStr(1)='?') then begin
  36.     writeln('Usage : DO operations    <- perform the "operations"');
  37.     writeln;
  38.     writeln('Valid unary operations (applied to one number) are :');
  39.     for i := 1 to MaxOperaciones do
  40.       write(arreglo[i]:MaxOpSize,'  ');
  41.     writeln;
  42.     writeln('Valid Constants are :');
  43.     for i := 1 to MaxConstantes do
  44.       with constantes[i] do
  45.         writeln('  ',letra,' = ',valor:22:12,' ... ',expln);
  46.     writeln;
  47.     writeln('Valid binary operations (between two numbers) are :');
  48.     writeln('  + (add)  - (subtract)  * (multiply)  / (divide)  ^ (elevate to)');
  49.     writeln;
  50.     writeln('Examples :');
  51.     writeln('  DO 5 + 4');
  52.     writeln('  DO p*2    <--- pi multiplied by 2');
  53.     writeln('  DO ln(e)  <--- this is the same as DO ln(exp(1))');
  54.     writeln('  DO -{2*5.5}/ [4.4*2^.5]');
  55.     halt(1);
  56.   end;
  57.   with rpn do begin
  58.     fun_string := '';
  59.     for i := 1 to ParamCount do
  60.       fun_string := fun_string + ' ' + ParamStr(i);
  61.     while fun_string[1]=' ' do
  62.       fun_string := copy(fun_string,2,length(fun_string)-1);
  63.   end;
  64. end;
  65.  
  66.  
  67. begin
  68.   writeln('DO.EXE   Version 1.5    Copyright (c) 1989 Bernardo Zamora');
  69.   ChecaParametros;
  70.  
  71.   writeln('----------------------------------------------------------');
  72.   writeln('Original expression = [',rpn.fun_string,']');
  73.  
  74.   { *** here we pass from normal to RPN notation *** }
  75.   Convierte_a_polaca (rpn);
  76.  
  77.   if rpn.error=0 then begin
  78.  
  79.     { *** here we evaluate the last converted expression *** }
  80.     result := Evalua_polaca(rpn,x_value);
  81.     if rpn.error=0 then begin
  82.       writeln('RPN Expression   = [',rpn.rpn_string,']');
  83.       writeln('Evaluated        = ',result:1:5);
  84.     end
  85.     else writeln('Error evaluating -->> ',rpn.message);
  86.   end
  87.   else writeln('Error converting -->> ',rpn.message);
  88. end.
  89.