[comp.lang.pascal] I need a formula parser for Turbo Pascal version 6.0

ms12@jaguar.ucs.uofs.edu (SCHWEISGUTH MICHAEL) (05/19/91)

 I need some Help ...

    I wrote some Numerical Analysis Integration Programs using the

 Simpsons method to find the area underneath the curve.  As of now, I

 store the function to be integrated in a Function declaration.  This

 makes it hard for a user with no Pascal Experience to use different

 functions since he or she must know how to use the editors-- including

 recompilation to use his or her new function. 

   Where can I get some code that would for example make some sense out

 of this statement :  (1 * X^2) + (2 * (9 + 2) ) ... meaning if X = 2, the

 function would return a value of 25.  

   Any help would be muchly appreciated.

  Thanks ...

            Tio Sancho. (MS12@Scranton)

ts@uwasa.fi (Timo Salmi) (05/20/91)

In article <618@platypus.uofs.edu> ms12@jaguar.ucs.uofs.edu writes:
:
>   Where can I get some code that would for example make some sense out
> of this statement :  (1 * X^2) + (2 * (9 + 2) ) ... meaning if X = 2, the
> function would return a value of 25.  
:

An extract from /pc/ts/tsfaq21.arc available from our site.

>From: ts@uwasa.fi
Subject: Writing an expression parser
Date: Sat 18 May 00:00:27 1991

27. *****
 Q: How to evaluate a function given as a string to the program?

 A: To do this you have to have a routine for parsing and evaluating
your expression. This is a complicated task requiring a clever use
of recursion. You can find such code in Stephen O'Brien (1988),
Turbo Pascal, The Complete Reference. Borland-Osborne/McGraw-Hill,
Chapter 10. Another, simpler piece of code can be found in Michael
Yester (1989), Using Turbo Pascal, Que, Chapter 5.
   I've also written such a function evaluation program myself, and
much of it is based on the ideas in O'Brien with my own corrections
and enhancements. The resulting program is available as fn.exe
function evaluator in the /pc/ts/tsfunc13.arc package (or whatever
version number is the latest). Note however, that the source code is
not included, nor available.
--------------------------------------------------------------------
...................................................................
Prof. Timo Salmi
Moderating at garbo.uwasa.fi anonymous ftp archives 128.214.12.37
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun

roth@oasys.dt.navy.mil (Pete Roth) (05/20/91)

You might take a look a the TCALC program Borland includes
with their distributions. It's a "small" spreadsheet
with a yacc-built parser you can extract and re-use.
It may be hard to change, but they _do_ give you the source code.

regards,

pete

- - - - - - - - - - - - - - - - - - - - - - - - - -
Peter N Roth      roth@oasys.dt.navy.mil
Objects in this office are closer than they appear.

roth@oasys.dt.navy.mil (Pete Roth) (05/21/91)

You might take a look a the TCALC program Borland includes
with their distributions. It's a "small" spreadsheet
with a yacc-built parser you can extract and re-use.
It may be hard to change, but they _do_ give you the source code.
regards,

pete

- - - - - - - - - - - - - - - - - - - - - - - - - -
Peter N Roth      roth@oasys.dt.navy.mil
Objects in this office are closer than they appear.