September 18, 2018
Hot Topics:

Simple Numerical Formula Parser

  • April 5, 2000
  • By Developer.com Staff
  • Send Email »
  • More Articles »

This article was contributed by Ralf Wirtz.

screen shot

Environment: VC6 SP3, Windows 95/98/NT/2000

The class CFormulaParser encapsulates a very useful mathematical parser for analytic/numerical formula transformation.

The formula dialog above is actually not necessary for the functionality but allows you comfortable to put in a formula string.

Hereby an extract from the header file:

class CFormulaParser  
 CString m_strFormula;
 CString m_strFunction;
 CString m_strErrortext;
 double m_dFktValue;
 double m_dFunctionConstant[ANZFUNKTKONST];
 CStringArray m_strStandardFunction;

 double SignFactor(WORD& nPosition, CString& strCharacter);
 double Expression(WORD& nPosition, CString& strCharacter);

 double SimpleExpression(WORD& nPosition, 
                         CString& strCharacter);

 double Term(WORD& nPosition, CString& strCharacter);
 double Factor(WORD& nPosition, CString& strCharacter);
 double Char_n(WORD& nPosition, CString& strCharacter);
 CString GetFormula();
 void SetFormula(CString Formula);
 void SetFunctConst(int index, double val);
 virtual ~CFormulaParser();

 double Calculation(CString strFormula, 
                    double xValue, 

The main method in CFormulaParser for the evaluation is:

double Calculation(CString strFormula, 
                   double xValue, 


  • strFormula is the formula string, e.g. "b*sin(x)/x"
  • xValue is in this case x, e.g. 3.14 (point instead comma!)
  • ErrorPosition gives back the error position in the string
  • Errortext gives back the corresponding error text

The parser is part of the program SimplexNumerica. For more information, please see my German website http://www.SimplexNumerica.de.


Download demo project (with source) - 104 Kb

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date