« elsdoerfer.name

TMathParser

A Delphi class for parsing mathematical terms. This is something I wrote a long time ago, and I fear it is probably really, really bad. While I can't actually confirm that, because I'm too afraid to look at the source code again, it is most likely so. But it also works (as far as I can remember anyway), so I'm putting it up here, and maybe it will be useful to someone.

The class first converts the input string into a pointer based tree stucture representing the formula. Syntax errors are caught at this point. By keeping the tree in memory you can speed up future calculations. This is mainly interesting if the formula contains variables and you need the evaulate it multiple times, e.g. when painting a graph.

About 50 predefined operators are included, but it is quite easy to define and add your own. Custom constants are also supported.

requirements

While I have only tested TMathParser with Delphi 7 and Delphi 6, it should work with previous versions as well.

download