Monday, April 27, 2009
C++ Math Parser
C++ Programmer? Do you need to parse mathematical expressions in C++? bcParserCPP Mathematical Expression Parser for C++ parses and evaluates math expressions given as strings at runtime. 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 C++ code, compile 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)", 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 simplified, very high level, birds eye view of the solution process.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment