TSthEvaluator: An expression evaluator

Version Information
Version: 0.3.2, updated: 2007-05-25
Developed with Delphi5, arithmetic evaluator
uSthEvaluator-0.3.2.zip (8KB, zipped source code).
0.3.2 fixes serious bugs with evaluating functions. Anyone should definitely upgrade.
Content
TSthEvaluator: An arithmetic evaluation class. Capable of variables.
Licence
uSthEvaluator.pas comes under the MIT licence. Have a look at the source file for further details. I am looking forward to feedback via eMail.

TSthEvaluator is an arithmetic evaluation class for Object Pascal (developed with Delphi 5). A given expression string is taken as input and numerically evaluated. You can use variables in the expression. Unknown variables will trigger an event where you may react and set the variable properly. Some constants are there as well and can easily be extended. Variable assignment and multiple evaluations per formula are possible.

Operator precedence is respected and parentheses are supported.

Some arithmetic functions such as sin, cos, abs, ceil, floor, round and some more are supported. It is easy to extend the evaluator to process other unary functions or binary operators.

Unary functions are functions that take one parameter, like sin(), cos(), sqrt(). Binary operators are what we normally use in everyday life. One operator with two arguments, like +, -, *, /, mod, div.

Examples

These are examples for valid formulas:
2*(2+a)
a=7+b; 8*a
7+b; 8*ans (same as above)
a=5; b=a*6
deg(2*pi)

Changelog

0.3–0.3.2 — 2007-05-25

  • Fixed a nasty bug with brackets
  • Fixed a bug with handling unary functions when they’re written without brackets. log 100 + log 100 was interpreted as log(100 + log(100))
  • Implemented OnNumber
  • Allow backslashes in numbers to enable the user to accept numbers like \b001 (you need to interpret \b yourself)
  • AllowVariablesWithCapitals implemented (needed, as normally, loweracse letters are for variables and upper case letters for numbers in other number systems like hex)
  • Added AllowEmptyAssignments as cosmetic property. This way a=; b=; are valid. I needed this at work.
  • added ld as synonym for log2 to the function list