# Board index » delphi » Evaluate a string math expression to a Float

## Evaluate a string math expression to a Float

I have a string, for exemple :   '((2*5)-(4+2))*10'

and i vould like the result : 40 in a variable X;

Do you have the function FUNC to make this ?

X : Real;

X := FUNC('((2*5)-(4+2))*10');

and now X = 40 ...

Think you very much

## Re:Evaluate a string math expression to a Float

In article <31965472.3...@inforoute.cgs.fr>,

##### Quote
Mike  <michael.ach...@inforoute.cgs.fr> wrote:

:I have a string, for exemple :   '((2*5)-(4+2))*10'
:and i vould like the result : 40 in a variable X;

tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

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
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 ftp://garbo.uwasa.fi/pc/ts/tsfunc13.zip
package (or whatever version number is the latest). Note however,
that the source code is not included, nor available.
Tips from Justin Lee (ossm...@rex.uokhsc.edu):
67666 Sep 22 1994 ftp://garbo.uwasa.fi/pc/tur{*word*77}j/parstp30.zip
parstp30.zip Recursive expression TP7.0/BP/VB/C++ parser, R.Loewy
An excellent parser is included with all the Turbo Pascal versions
since TP4.0 as part of the MCALC or TCALC spreadsheet example
program. See mcparse.pas or tcparse.pas.
--------------------------------------------------------------------

All the best, Timo

....................................................................
Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
t...@uwasa.fi http://uwasa.fi/~ts BBS 961-3170972; FIN-65101,  Finland