If you would like to submit an article, click the button below.
By: David Dale, Mon Aug 25th, 2008
Are you a programmer? Do you need to parse mathematical expressions? If yes, I would like to tell you about bcParserX Mathematical Expression Parser COM Component to parse and evaluate math expressions in Visual Basic, Visual C++, C# (CSharp), .NET, Delphi and even Excel. Parsing formulas given as strings at runtime is a challenge for any programmer when he wants to allow the user input a mathematical formula. It is easy to compute mathematical expressions that are known at compile time. We type it in our program and when we execute our program, we get the result. For example x+sin(x) can be easily computed when the value of x is supplied. However, when the mathematical expression is given as a string at runtime, for example "x+sin(x)", then, to the program, it is no different then a meaningless "abc". The programmer has to make an explicit effort to make the program understand that there is a plus (+) sign that adds the value of x and the value of sin(x). Of crourse, the program also needs to understand the concept of a function call such as "sin(x)". The concept of breaking such an expression into it's conceptual sub-sections is called parsing. The programmer writes code which typically creates a data structure which represents the mathematical expression in a way that can be used to evaluate it efficiently. This is a gross simplification of the process but that is how it looks from a very high level, birds eye view. bcParserX Math Parser COM Component simplifies the task for us by implementing the parse and evaluate algorithm. The expression is first parsed into an expression tree. Once this is done, the compiled tree structure is re-used with different variable results to achieve very fast evaluation performance. COM is a binary standard to implement pluggable software components. It is possible to use a COM component from any COM client such as Visual Basic.NET, C#, Visual C++, Delphi, or even Visual Basic Script in Excel. COM is an ideal technology to create re-usable software components that can be consumed by clients independent of implementation language. bcParserX Math parser is implemented in Visual C++ which generates very fast executables that are ideal for high performance numerical computing. Visual C++ also allows us to control floating point operation details. For example, bcParserX allows the user to specify whether division by zero is allowed or not. The Math Parser reports error via standard COM mechanisms. In Visual C++, this is an HRESULT indicating failure, and in C#, VB it is a COMException. Tackling all of the challenges of implementing a parser is almost impossible within the scope of a broader project where there are pressing requirements in terms of time and functionality to be delivered. Most of us need to focus on the actual business problem at hand and view the mathematical expression parsing aspect of the problem as a side issue. Thus, it becomes very very hard to deliver correct, united tested, proven code on time and in budget. Trying to code a expression parser could take an experienced developer a month to write and to test. When such as road block appears, the best way is to find a good component that can easily be integrated into your development project, leaving you free time to focus on other aspects of your project or to simply go home and rest. There is peace of mind in using a component that many others have used for many years and flushed out the bugs for you. bcParserX math parser com component allows the programmer control many aspects of it's behaviour. For example it allows the programmer define his own variables, create user defined functions and it report proper error messages that can eventually be displayed to the end user. bcParserX is an ideal choice when you need a fast math parser that has stood the test of time with multiple language support.