dcsimg

Simple Numerical Formula Parser

WEBINAR:
On-Demand

Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


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  
{
private:
 //Implementation
 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);
				 
public:
 CString GetFormula();
 void SetFormula(CString Formula);
 void SetFunctConst(int index, double val);
	
 CFormulaParser();
 virtual ~CFormulaParser();

//Interface
 double Calculation(CString strFormula, 
                    double xValue, 
                    WORD& 
                    ErrorPosition, 
                    CString& 
                    Errortext);
};
The main method in CFormulaParser for the evaluation is:
double Calculation(CString strFormula, 
                   double xValue, 
                   WORD& 
                   ErrorPosition, 
                   CString& 
                   Errortext);
where
  • 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

Download demo project (with source) - 104 Kb


Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

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