comp.lang.ada
 help / color / mirror / Atom feed
* Looking for calc. package in Ada
@ 1996-06-25  0:00 Strategies SA
  1996-06-27  0:00 ` Gary McKee
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Strategies SA @ 1996-06-25  0:00 UTC (permalink / raw)



Hello
I'm looking for a package looking like :

package CALCULATOR is 
   ...
   procedure STORE_VARIABLE is (NAME : STRING;
				VALUE : FLOAT);

   function CALCULATE (EXPRESSION : STRING) 
	return FLOAT;
   ...
end CALCULATOR;

In order to use it the following way 
   ...
   CALCULATOR.STORE_VARIABLE ("A", 10.0);
   ...
   RESULT := CALCULATOR.EVALUATE ("10*COS(A)");
   ...
Does anybody know where I can find (good) inspiration ? 
Thank You in advance

Jerome HAGUET
Strategies 
France




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Looking for calc. package in Ada
  1996-06-25  0:00 Looking for calc. package in Ada Strategies SA
  1996-06-27  0:00 ` Gary McKee
@ 1996-06-27  0:00 ` Nasser Abbasi
  1996-06-28  0:00 ` k. beitz
  2 siblings, 0 replies; 4+ messages in thread
From: Nasser Abbasi @ 1996-06-27  0:00 UTC (permalink / raw)
  To: Strategies SA


   From: Strategies SA <100747.2001@CompuServe.COM>
   Newsgroups: comp.lang.ada
   Date: 25 Jun 1996 17:34:54 GMT

   Hello
   I'm looking for a package looking like :

   package CALCULATOR is 
      ...
      procedure STORE_VARIABLE is (NAME : STRING;
				   VALUE : FLOAT);

      function CALCULATE (EXPRESSION : STRING) 
	   return FLOAT;
      ...
   end CALCULATOR;

   ..snip..


you might want to look at the Beitz calculator package, one of the
ARA Ada contest programs, I dont know if it does what you want, but
you might be abe to steal some code or idea from it. this is the
main line of it: (it is a Xwindows Ada application)
ps. the programs are located in  ftp://ocsystems.com/pub/ara-contest/2.

with Value.Input.X_GUI;

procedure XAdaCalc is

    --| OVERVIEW
    --|
    --| This is the main procedure for the AdaCalculator.
    --|
    --| IMPLEMENTATION
    --|
    --| 1. call the creation routine for the GUI (a complex of buttons, mostly)
    --| 2. run
    --| 3. wait for the TurnOffCalculator exception

begin
    Value.Input.X_GUI.Create_Calculator;
    Value.Input.X_GUI.Run_Calculator;
exception
    when Value.Input.X_GUI.Turn_Calculator_Off => null;
end XAdaCalc;
-- 
Nasser Abbasi. C/C++/Ada Solaris. GeneAssist - A client/server application 
for Nucleic acid and protein sequence search and analysis. 
PE-Applied BioSystem division. email:  nasser@apldbio.com   
MSEE(control), MSCS, MSCE, FM(Fide Chess Master 1.e4 !!   1-0 )






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Looking for calc. package in Ada
  1996-06-25  0:00 Looking for calc. package in Ada Strategies SA
@ 1996-06-27  0:00 ` Gary McKee
  1996-06-27  0:00 ` Nasser Abbasi
  1996-06-28  0:00 ` k. beitz
  2 siblings, 0 replies; 4+ messages in thread
From: Gary McKee @ 1996-06-27  0:00 UTC (permalink / raw)


In article <4qp7vu$c9f$1@mhafn.production.compuserve.com>,
Strategies SA <100747.2001@CompuServe.COM> wrote:

 > Hello
 > I'm looking for a package looking like :
 > 
 > package CALCULATOR is 
 >    ...
 >    procedure STORE_VARIABLE is (NAME : STRING;
 > 				VALUE : FLOAT);
 > 
 >    function CALCULATE (EXPRESSION : STRING) 
 > 	return FLOAT;
 >    ...
 > end CALCULATOR;
 > 
 > In order to use it the following way 
 >    ...
 >    CALCULATOR.STORE_VARIABLE ("A", 10.0);
 >    ...
 >    RESULT := CALCULATOR.EVALUATE ("10*COS(A)");
 >    ...
 > Does anybody know where I can find (good) inspiration ? 
 > Thank You in advance
 > 
 > Jerome HAGUET
 > Strategies 
 > France

---------------------------------------------------------------
I don't have an Ada package to do this. However, There is a simple dseign
(in C++) if you decide to implement it yourself.

"The C++ Programming Language" by Bjarne Stroustrup (2nd edition) has a
simple interactive calculator in Chapter three that could be a basis for
your Ada package.








^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Looking for calc. package in Ada
  1996-06-25  0:00 Looking for calc. package in Ada Strategies SA
  1996-06-27  0:00 ` Gary McKee
  1996-06-27  0:00 ` Nasser Abbasi
@ 1996-06-28  0:00 ` k. beitz
  2 siblings, 0 replies; 4+ messages in thread
From: k. beitz @ 1996-06-28  0:00 UTC (permalink / raw)


nasser@apldbio.com (Nasser Abbasi) writes:

> 
> 
>    From: Strategies SA <100747.2001@CompuServe.COM>
>    Newsgroups: comp.lang.ada
>    Date: 25 Jun 1996 17:34:54 GMT
> 
>    Hello
>    I'm looking for a package looking like :
> 
>    package CALCULATOR is 
>       ...
>       procedure STORE_VARIABLE is (NAME : STRING;
> 				   VALUE : FLOAT);
> 
>       function CALCULATE (EXPRESSION : STRING) 
> 	   return FLOAT;
>       ...
>    end CALCULATOR;
> 
>    ..snip..
> 
> 
> you might want to look at the Beitz calculator package, one of the
> ARA Ada contest programs, I dont know if it does what you want, but
> you might be abe to steal some code or idea from it. this is the
> main line of it: (it is a Xwindows Ada application)
> ps. the programs are located in  ftp://ocsystems.com/pub/ara-contest/2.
> 

being the author of this calculator, i can tell you that the intention of the
calculator was to fit as an engine into a scheme like you've described.

i can tell you that there is a variation in the contest directory that will
run on a normal tty type terminal.  the value.input.x_gui is the child of
input that supports an X GUI, and the value.input.text child is the one that
supports text only input.  it is from value.input.text that you should be
able to find the best source to start from

by having calculate call something akin to the procedure Value.Input.Dispatch
(which currently only appears in Value.Input.Text.Process, but could be
presumably cut-and-paste into the package at the bottom) -- on each character
of the string, and having the display refresh update the string that gets
returned by Calculate, you could achieve what you want.  (in the example
below, i've made calculate return a string instead of a float, but
presumably, you could just call float_io.Get on the string to get a float
value for other purposes).

internally, the way it does calculations is via an abstract tagged type
expression, extensions of that tagged type type for every kind of evaluatable
expression, and parsing based on the current input value.

-------------------------------------------------------------------------------

package calculator is

    procedure Refresh( S : String );

    function Calculate( Expression : String ) return String;
	
end calculator;

with Calculator;
procedure Display_Refresh( S : String ) is	-- with'ed by Value package
begin
    Refresh( S );
end Display_Refresh;

package Value.Input.Whole_String is

    procedure Dispatch( C : Character );

end Value.Input.Whole_String;

package body Value.Input.Whole_String is

    -- cut-and-paste here from Value.Input.Text.Dispatch as necessary
    -- it includes some things for text style popup menus and stuff you can
    -- probably ignore 

end Value.Input.Whole_String;

with Ada.Strings.Unbounded;
with Value.Input.Whole_String;
package body calculator is

    Display : Ada.Strings.Unbounded.Unbounded_String;

    procedure Refresh( S : String ) is
    begin
	Display := Ada.Strings.Unbounded.To_Unbounded_String( S );
    end Refresh;

    function Calculate( Expression : String ) return String is
    begin
	for E in Expression'RANGE loop
	    Value.Input.String_At_A_Time.Dispatch( Expression(E) );
	end loop;
	return Ada.Strings.Unbounded.To_String( Display );
    end Calculate;

end Calculator;

-- now, compile all of the value tree, create your main that calls
-- Calculator.Calculate, and you're good to go.

--kirk beitz





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-06-28  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-25  0:00 Looking for calc. package in Ada Strategies SA
1996-06-27  0:00 ` Gary McKee
1996-06-27  0:00 ` Nasser Abbasi
1996-06-28  0:00 ` k. beitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox