Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Expression evaluator

Title: Expression evaluator Question: The components perform high-speed (about 10 million evaluations per second) mathematics and boolean calculations. All components are available for Delphi 5, Delphi 6, Delphi 7, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE. Answer: Available material consists of the following parts: 1) CalcUtils unit is intended for the quick calculation of any expression; 2) TParser component is the calculation engine. It is suitable for calculation of large amount different expressions. It implements compiling the expression into the byte code and using it in the following calculations; 3) TCalculator component is fully-functional, stand-alone mathematics and multi-threaded shell for the parser. It differs from TParser by having additional mechanisms for reaching the best performance. Components and units, mentioned above, contain a number of high-speed simple methods having the singular input parameter of string type, which represents the mathematics expression, and returning the number (AsByte, AsInteger, AsBoolean, etc.). It makes possible using the parse components at any time without unnecessary understanding the internal parse mechanisms. It is possible making a user-defined functions, variables, constants and types. It is also possible making a direct reference to the simple variable of type like Byte, Integer, etc. Parse components have being developed for 8 years till now to reach the best result according their philosophy being fast in calculations and easy in use. Please note that the samples do not require components installation (however installation is possible and in case when installed you find the components on "Samples" page of the pallete). You may open the Delphi project file (*.dpr) in the sample folder and simply run it.