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 <>,

Mike  <> wrote:

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

 98471 Apr 28 1996 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
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
package (or whatever version number is the latest). Note however,
that the source code is not included, nor available.
   Tips from Justin Lee (
 67666 Sep 22 1994{*word*77}j/ 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:// & archives
Department of Accounting and Business Finance  ; University of Vaasa BBS 961-3170972; FIN-65101,  Finland

Other Threads