Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!fuug!funic!news.funet.fi!uwasa.fi!ts From: ts@uwasa.fi (Timo Salmi) Newsgroups: comp.lang.pascal Subject: Re: I need a formula parser for Turbo Pascal version 6.0 Message-ID: <1991May19.170948.26725@uwasa.fi> Date: 19 May 91 17:09:48 GMT References: <618@platypus.uofs.edu> Organization: University of Vaasa, Finland Lines: 34 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