我想知道yall是否知道如何构造我在下面的参数“input”,以便它可以被抛入解析器并用于创建树。这是一个基于类并使用变量表达式的中缀后缀程序。如果您需要更多信息,请告诉我
arithmetic_expression::arithmetic_expression(RPNstring input) //constructor
{
}
arithmetic_expression::arithmetic_expression(const arithmetic_expression &inExpression)
{
}
来自
的Rpnstring#ifndef AE_H
#define AE_H
class RPNstring
{
public:
RPNstring(std::string inString){ expression = inString; };
std::string getString(){return(expression);}
private:
std::string expression;
};
class Infixstring
{
public:
Infixstring(std::string inString){ expression = inString; };
std::string getString(){return(expression);};
private:
std::string expression;
};
class arithmetic_expression
{
public:
arithmetic_expression(RPNstring inString);
arithmetic_expression(Infixstring inString);
arithmetic_expression(const arithmetic_expression &inExpression); //Copy constructor
~arithmetic_expression(); //Destructor
arithmetic_expression & operator=(const arithmetic_expression &inExpression); //assignment operator
void printRPN();
void printInfix();
int evaluate_Expression(std::map< std::string, int > ipmap);
和
RPNstring in1("3 2 + xyz *");
arithmetic_expression expression1(in1);
std::cout<<"Expression 1"<< std::endl;
expression1.printInfix();
expression1.printRPN();
std::cout<<"----
和来自
的inStringclass Tree
{
public:
Tree(std::string input,Tree *leftSubTree=NULL,Tree *rightSubTree=NULL);
Tree(const Tree &inTree); //COPY CONSTRUCTOR
~Tree(); //DESTRUCTOR
还有...
Tree::Tree(std::string input,Tree *leftSubTree,Tree *rightSubTree){
Op = input;
leftPtr = leftSubTree;
rightPtr = rightSubTree;
int num;
if (input == "+"|input == "-"|input == "*"|input == "/")
NodeType = TYPE_OPERATOR;
else if(std::istringstream(Op)>>num)
NodeType = TYPE_NUMBER;
else
NodeType = TYPE_VARIABLE;