本文整理汇总了C++中ExpressionNode::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionNode::GetType方法的具体用法?C++ ExpressionNode::GetType怎么用?C++ ExpressionNode::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionNode
的用法示例。
在下文中一共展示了ExpressionNode::GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConvertInfixToPostfix
void Expression::ConvertInfixToPostfix()
{
if (!m_PostfixExpression.empty() || m_InfixExpression.empty())
return;
m_Result = true;
m_Status = true;
std::stack<ExpressionNode> stackOperator;
ExpressionNode::ExpressionNodeType lastType = ExpressionNode::Unknown;
for (PostfixVector::size_type i = 0; i < m_InfixExpression.size(); ++i)
{
ExpressionNode expNode;
expNode.Initialize(m_InfixExpression[i]);
const ExpressionNode::ExpressionNodeType type = expNode.GetType();
if (type == ExpressionNode::Numeric)
{
// Operand, add to postfix expression
m_PostfixExpression.push_back(expNode);
while (!stackOperator.empty() && stackOperator.top().IsUnaryOperator())
{
m_PostfixExpression.push_back(stackOperator.top());
stackOperator.pop();
}
}
else if (type == ExpressionNode::LParenthesis)
{
// Left Parentheses, add to stack
stackOperator.push(expNode);
}
else if (type == ExpressionNode::RParenthesis)
{
// Right Parentheses, reverse search the Left Parentheses, add all operator of the middle
ExpressionNode node;
while (!stackOperator.empty())
{
node = stackOperator.top();
stackOperator.pop();
if (node.GetType() == ExpressionNode::LParenthesis)
{
while (!stackOperator.empty() && stackOperator.top().IsUnaryOperator())
{
m_PostfixExpression.push_back(stackOperator.top());
stackOperator.pop();
}
break;
}
else
m_PostfixExpression.push_back(node);
}
// The lastest node must be Left Parentheses
if (node.GetType() != ExpressionNode::LParenthesis)
{
m_Status = false;
}
}
else
{
if (ExpressionNode::IsUnaryNode(type) && (m_PostfixExpression.empty() ||
(lastType != ExpressionNode::Unknown &&
lastType != ExpressionNode::RParenthesis &&
lastType != ExpressionNode::Numeric)))
{
expNode.SetUnaryOperator();
stackOperator.push(expNode);
}
else if (stackOperator.empty())
{
stackOperator.push(expNode);
}
else
{
ExpressionNode beforeExpNode = stackOperator.top();
if (beforeExpNode.GetType() != ExpressionNode::LParenthesis &&
beforeExpNode.GetPriority() >= expNode.GetPriority())
{
m_PostfixExpression.push_back(beforeExpNode);
stackOperator.pop();
}
stackOperator.push(expNode);
}
}
lastType = type;
}
while (!stackOperator.empty())
{
ExpressionNode beforeExpNode = stackOperator.top();
if (beforeExpNode.GetType() == ExpressionNode::LParenthesis)
{
m_Status = false;
}
m_PostfixExpression.push_back(beforeExpNode);
stackOperator.pop();
}
#ifdef CC_PARSER_TEST
wxString infix, postfix;
//.........这里部分代码省略.........