// Expression.h: interface for the CExpression class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_EXPRESSION_H__2578E33F_FF86_4384_A7CE_A401BAC5A010__INCLUDED_)
#define AFX_EXPRESSION_H__2578E33F_FF86_4384_A7CE_A401BAC5A010__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <list>
#include <string>
using namespace std;
#define DELIMITER 1 //分隔符
#define VARIABLE 2 //变量
#define NUMBER 3 //数值
#define FUNCTION 4 //函数
#define PI 3.1415926535898
class CVar //用来存放变量及变量值的表结构
{
public:
char m_cFlag; // 等于0为临时变量,否则等于1
string m_strName; //变量名 如变量a
string m_strSlave; //约束表达式,如a=b+2
double m_dValue; //变量值 如10,表a=10
public:
CVar();
virtual ~CVar();
void InitVar();
};
class CVarList
{
public:
list<CVar*> m_VarList;
CVarList();
virtual ~CVarList();
bool AddVar(CVar* pVar);
};
class CExpression
{
public:
double m_dResult;
char* m_strExp;
CVarList m_VarList;
bool m_bDegUnit; // 缺省采用角度单位
protected:
int m_iErrFlag; //标记表达式计算是否出错0:正常,1:表达式空2:非法变量或函数3:括号不匹配
int m_iFunFlag; //标记当前正在进行函数参数计算.
int m_iMatchFlag; //标记括号是否匹配
char m_cTokenType; //标记符号的类型,如分格符,变量等
char m_strToken[80];
public:
void Message(const char * strMsg);
CExpression();
virtual ~CExpression();
bool CalExp();
bool UpdateSlaveVar();
protected:
bool GetToken();
void Error();
bool IsDelim(char c);
bool IsFunc(const char *fname);
bool IsWhite(char c);
bool IsInStr(char ch,char *s);
bool Level1(double *result);
bool Level2(double *result);
bool Level3(double *result);
bool Level4(double *result);
bool Level5(double *result);
bool Level6(double *result);
bool Level7(double *result);
bool GetFunIndex(const char *name,int *index);
void PutBack();
void Unary(char o,double *r);
bool Arith(char o, double *r, double *h);
bool Primitive(double *result);
bool GetVarValue( const char * n, double * result );
bool GetVarIndex( const char * name, int * index );
};
#endif // !defined(AFX_EXPRESSION_H__2578E33F_FF86_4384_A7CE_A401BAC5A010__INCLUDED_)
本文地址:http://com.8s8s.com/it/it1403.htm