Sto provando a fare un parser di expr matematiche.
Ho creato la mia bella classina ma ho un problema
codice:
#include <list>
#include <string>

// The expression operator enum
typedef enum
{
	PLUS = 0,
	MINUS,
	DIV,
	MOD
} OpType;

// The Expression
struct ExprOp
{
	OpType op;
	std::string op1;
	std::string op2;
	ExprOp(const std::string &Op1, const std::string &Op2, OpType Op)
	{
		op1 = Op1;
		op2 = Op2;
		op =  Op;
	}
};

typedef std::list<ExprOp *> Expression;
typedef std::list<ExprOp *>::iterator Expression_it;

class CExprParse
{
	private:
		std::string ris;
		Expression expr;
		bool ParseEspr(const std::string &value);
	public:
		CExprParse();
		~CExprParse();
		CExprParse(CExprParse &p);
		bool Exec();
		inline const std::string Get();
		bool addExpr(const std::string &value);
};

CExprParse::CExprParse()
{
}

CExprParse::CExprParse(CExprParse &p)
{
	// no autoassignment
	if(&p != this)
	{
		// TODO
	}
}

CExprParse::~CExprParse()
{
}

bool CExprParse::ParseEspr(const std::string &value)
{
	unsigned int plus_loc =  value.find( "+", 0 );
	unsigned int minus_loc = value.find( "-", 0 );
	unsigned int div_loc =   value.find( "/", 0 );
	if(plus_loc != std::string::npos) 
	{
		expr.push_back(new ExprOp(value.substr( 0, minus_loc ), value.substr( minus_loc, value.size() ),PLUS));
		return true;
	}
  else if(minus_loc != std::string::npos)
	{
		expr.push_back(new ExprOp(value.substr( 0, minus_loc ), value.substr( minus_loc, value.size() ), MINUS));
		return true;
	}
  else if(div_loc != std::string::npos)
  {
  	expr.push_back(new ExprOp(value.substr( 0, minus_loc ), value.substr( minus_loc, value.size() ), DIV));
  	return true;
  }else
  {
  	return false;
  }
}

bool CExprParse::addExpr(const std::string &value)
{
	return (ParseEspr(value));
}

bool CExprParse::Exec()
{
	std::string tmp("");
	ExprOp * ex;
	// IF EMPTY EXIT
	if(expr.empty())
		return false;
	while(!expr.empty())
	{
		// RETURN THE PART OF EXRESSION TO EXECUTE
		ex = expr.front();
		//////////////////////////////////////////
		///////// CHECK THE LITTERAL /////////////
		//std::string f_l = ;
		//std::string s_l = ;
		/*
			if(f_l == s_l) // ax + bx
			{
				switch(ex.op)
				{
					case PLUS:
						break;
					case MINUS:
						break;
					case DIV:
						break;
				}
			}else // ax + by
			{
        switch(ex.op)
				{
					case PLUS:
						break;
					case MINUS:
						break;
					case DIV:
						break;
				}
			}
		*/
		//////////////////////////////////////////
		//////////CHECK THE NUMBERICAL ///////////
		//int fist = static_cast< int >();
		//int second = static_cast< int >();
		//////////////////////////////////////////
		////////// EXEC THE OPERARATION //////////
		
		// REMOVE THE ELEMENT
		expr.pop_front();
	}
	return true;
}

const std::string CExprParse::Get()
{	
	if(Exec())
		return ris;
	else
 		new std::string("Can't execute the expression\n");	
}
Come proseguo????
La mia implementazione del metodo Exec va bene????

Tnk 10000000000000