本文整理汇总了C++中Token::SetType方法的典型用法代码示例。如果您正苦于以下问题:C++ Token::SetType方法的具体用法?C++ Token::SetType怎么用?C++ Token::SetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::SetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char * argv [])
{
WCS_String temp;
char op;
char character;
long i;
long val;
MathTree mathTree;
Token token;
cout<<"********************** Welcome to the MathTree Calculator!! ********************" << endl;
cout<<"Enter 'C' followed by a whole number to enter a constant in the tree" <<endl;
cout<<"Enter 'V' followed by two digits to enter a variable into the tree" <<endl;
cout<<"Enter 'v' followed by two digits, a space, and then up to three digits"<<endl;
cout<<"To set a value to your variable" <<endl;
cout<<"Enter 'O' followed by and operator (+ - * /) followed by a digit "<<endl;
cout<<"To insert an operator into the tree with a percedence set by the digit"<<endl;
cout<<"Enter 'E' to evaluate the tree and to see what the answer is" <<endl;
cout<<"Enter 'D' to delete the tree" <<endl;
cout<<"Enter 'X' to exit the program"<<endl;
cout<<endl;
cout<<"\t\t\t ENTER A VALID IMPUT " <<endl;
for(;;)
{
character = cin.get();
switch (character)
{
case 'c':
case 'C':
cin >> i;
cin.ignore ();
cout<<"you entered a constant "<< i << endl;
cout<<"\n"<<endl;
token.SetType (Token::ConstantToken); // move SetType from private to public in tokenn class
token.SetValue (i);
mathTree.InsertOperand (token);
break;
case 'V':
cin >> i;
cin.ignore ();
cout<<"You want to enter the variable " << i <<endl;
token.SetType (Token::VariableToken);
token.SetWhich (i);
mathTree.InsertOperand (token);
cout<<"You entered the variable "<<token.GetWhich() <<endl;
cout<<"\n"<<endl;
break;
case 'e':
case 'E':
try{
cout << "Answer is " << mathTree.Evaluate () << endl;
cout<<"\n"<<endl;
}
catch(MathTree::Exceptions E){
switch (E){
case 0:
cout<<"cannot divide by 0 exiting program.. "<< endl;
exit (0);
}
}
break;
case 'v':
cin >> i;
cin >> val;
cin.ignore ();
cout<<"You want to set the variable " << i << " To the value " << val <<endl;
token.SetType (Token::VariableToken);
token.SetWhich (i);
token.SetValue (val);
cout<<"the variables value is "<<token.GetValue()<<endl;
cout<<"\n"<<endl;
break;
case 'X':
case 'x':
exit (0);
break;
case 'O':
case 'o':
cin >> op;
cin >> val;
cin.ignore ();
cout<<"You Entered a " << op << " Operator " << endl;
cout<<"You want to set the " << op << " Operator's precedence to " << val << endl;
if (op == '+'){
token.SetType(Token::OperatorPlusToken);
token.SetPrecedence((Operator::Precedence)(val));
mathTree.InsertBinaryOperator (token);
cout<<"operators precedence is : " << token.GetPrecedence() << endl;
cout<<"\n"<<endl;
}
else
if (op =='-'){
token.SetType(Token::OperatorMinusToken);
token.SetPrecedence((Operator::Precedence)(val));
mathTree.InsertBinaryOperator (token);
cout<<"operators precedence is : " << token.GetPrecedence() << endl;
cout<<"\n"<<endl;
}
else
if (op == '*'){
//.........这里部分代码省略.........
示例2: main
void main ()
{
char c;
int i;
int numParen;
char op;
long Value;
MathTree MT;
Token Toke;
Token::TokenType DetermineTokenType(char);
Operator::Precedence DetermineLePrecedence(char, int);
void Halp();
Halp();
for (;;)
{
c = cin.get (); //get the first char
switch (c)
{
case 'c':
case 'C':
cin >> i; // we are just going to ASSume this input is perrrrfect.
Toke.SetType (Token::ConstantToken);
Toke.SetValue (i);
MT.InsertOperand (Toke);
break;
case 'o':
case 'O':
cin >> op;
cin >> numParen;
Toke.SetType( DetermineTokenType(op) );
Toke.SetPrecedence( DetermineLePrecedence(op, numParen) );
MT.InsertBinaryOperator(Toke);
break;
case 'V':
cin >> i;
cin.ignore ();
Toke.SetType (Token::VariableToken);
Toke.SetWhich (i);
MT.InsertOperand (Toke);
break;
case 'e':
case 'E':
try{
cout << "Answer is " << MT.Evaluate () << endl;
}
catch(...)
{
cout << "Diving by zero is bad. mmmkay?." << endl;
cout << "Deleting tree" << endl;
MT.DeleteTree();
cout << "Tree deleted, try again." << endl;
}
break;
case 'v':
cin >> i;
cin >> Value;
cin.ignore ();
Toke.SetType (Token::VariableToken);
Toke.SetWhich (i);
Toke.SetValue (Value);
break;
case 'd':
case 'D':
MT.DeleteTree();
break;
case 'x':
case 'X':
exit(0);
break;
case 'h':
case 'H':
Halp();
}
}
}