本文整理汇总了C++中ASTNode::prependChild方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode::prependChild方法的具体用法?C++ ASTNode::prependChild怎么用?C++ ASTNode::prependChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTNode
的用法示例。
在下文中一共展示了ASTNode::prependChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASTNode
/**
* In MathML, <plus/> and <times/> are n-ary operators but the infix
* FormulaParser represents them as binary operators. To ensure a
* consistent AST representation, this function is part of the n-ary to
* binary reduction process.
*/
static void
reduceBinary (ASTNode& node)
{
if (node.getNumChildren() == 2)
{
ASTNode* op = new ASTNode( node.getType() );
node.swapChildren(op);
node.prependChild(op);
}
}
示例2: if
/**
* Ensures the given ASTNode has the appropriate number of arguments. If
* arguments are missing, appropriate defaults (per the MathML 2.0
* specification) are added:
*
* log (x) -> log (10, x)
* root(x) -> root( 2, x)
*/
static void
checkFunctionArgs (ASTNode& node)
{
if (node.getNumChildren() == 1)
{
if (node.getType() == AST_FUNCTION_LOG)
{
ASTNode* child = new ASTNode;
child->setValue(10);
node.prependChild(child);
}
else if (node.getType() == AST_FUNCTION_ROOT)
{
ASTNode* child = new ASTNode;
child->setValue(2);
node.prependChild(child);
}
}
}