当前位置: 首页>>代码示例>>C++>>正文


C++ TreeNode::appendChild方法代码示例

本文整理汇总了C++中TreeNode::appendChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeNode::appendChild方法的具体用法?C++ TreeNode::appendChild怎么用?C++ TreeNode::appendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeNode的用法示例。


在下文中一共展示了TreeNode::appendChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: If

TreeNode* Parser::If()
{
	TreeNode* node = new TreeNode(currentToken, ifNode);
	preservedToken = currentToken;
	matchToken(tokIf);

	node->appendChild( Expression() );

	if (currentToken.type == tokDo) getToken(); // skip dummy word 'do'

	if (currentToken.type == tokBegin) node->appendChild( Block() ); // if followed by a block
	else node->appendChild( Statement() ); // if followed by single statement

	while (currentToken.type == tokEOL) getToken(); // allow the else keyword to be on later lines

	if (currentToken.type == tokElse) // else part
	{
		matchToken(tokElse);
		while (currentToken.type == tokEOL) getToken();
		if (currentToken.type == tokDo) getToken(); // next word

		if(currentToken.type == tokBegin) node->appendChild( Block() ); // else is followed by block
		else node->appendChild( Statement() );
	}

	return node;
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2: Program

TreeNode* Parser::Program()
{
	Token emptyToken;
	emptyToken.type = tokNotSet;
	emptyToken.look = "";
	emptyToken.start.row = 0;
	emptyToken.start.col = 0;
	emptyToken.end.row = 0;
	emptyToken.end.col = 0;

	TreeNode* program = new TreeNode(emptyToken, programNode, "program");
	TreeNode* block = new TreeNode(emptyToken, blockNode, "block");

	getToken();

	// this is the main parse loop
	kdDebug(0)<<"Parser::Program(): entering main parse loop..."<<endl;
	while (currentToken.type != tokEOF) // currentToken.type returns the type of the currentToken
	{
		kdDebug(0)<<"Parser::Program(), [main parse loop]: looking for next statement..."<<endl;
		block->appendChild( Statement() );
		while (currentToken.type == tokEOL) getToken(); // newlines between statements are allowed
		// runs statement related code, stores the returned TreeNode* in the nodetree
		// note: Statement() allways gets a new Token with getToken() before it returns
	}
	program->appendChild(block);
	kdDebug(0)<<"Parser::Program(): leaving main parse loop..."<<endl;

	return program;
}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例3: Learn

TreeNode* Parser::Learn()
{
	preservedToken = currentToken;
	matchToken(tokLearn); // skip the 'dummy' command
	TreeNode* func = new TreeNode(currentToken, functionNode);
	getToken(); // get the token after the function's name

	TreeNode* idList = new TreeNode(currentToken, idListNode, "idlist");
	if (currentToken.type != tokBegin)
	{
		if (currentToken.type == tokUnknown) idList->appendChild( getId() );
		else
		{
			Error(currentToken, "Expected a parameter name or a '[' after the learn command.", 3030);
			getToken(); // this recovers from the error
		}
		
		while (currentToken.type == tokComma)
		{
			matchToken(tokComma);
			idList->appendChild( getId() );
		}
	}
	func->appendChild(idList);

	learnedFunctionList.append( func->getLook() ); // publish the function

	func->appendChild( Block() );

	return func;
}
开发者ID:,项目名称:,代码行数:31,代码来源:

示例4: FunctionCall

TreeNode* Parser::FunctionCall(Token maybeFunctionCall)
{
	kdDebug(0)<<"Parser::FunctionCall() [using identifier: '"<<maybeFunctionCall.look<<"']"<<endl;
	TreeNode* fcall = new TreeNode(maybeFunctionCall, functionCallNode);

	TreeNode* paramList = new TreeNode(currentToken, idListNode, "idlist");
	// if (currentToken.type != tokEOL && currentToken.type != tokEOF)
	if (currentToken.type == tokNumber ||
	    currentToken.type == tokString ||
	    currentToken.type == tokUnknown) // only if there is a possible parameter given after the call...
	{
		TreeNode* expr = Expression();
		if (expr->getType() == Unknown) Error(currentToken, i18n("Expected an expression"), 1020);
		else paramList->appendChild(expr);
		while (currentToken.type == tokComma)
		{
			matchToken(tokComma);
			expr = Expression();
			if (expr->getType() == Unknown) Error(currentToken, i18n("Expected an expression"), 1020);
			else paramList->appendChild(expr);
		}
	}
	fcall->appendChild(paramList);

	return fcall;
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例5: Repeat

TreeNode* Parser::Repeat()
{
	TreeNode* node = new TreeNode(currentToken, RepeatNode);
	preservedToken = currentToken; // preserve token, else Match() will make sure it gets lost
	matchToken(tokRepeat);
	node->appendChild( Expression() );
	node->appendChild( Block() );
	return node;
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例6: While

TreeNode* Parser::While()
{
	TreeNode* node = new TreeNode(currentToken, whileNode);
	preservedToken = currentToken;
	matchToken(tokWhile);
	node->appendChild( Expression() );
	node->appendChild( Block() );
	return node;
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例7: ForEach

TreeNode* Parser::ForEach()
{
	TreeNode* fNode = new TreeNode(currentToken, forEachNode);
	preservedToken = currentToken;
	matchToken(tokForEach);

	fNode->appendChild( Expression() );
	matchToken(tokIn);
	fNode->appendChild( Expression() );

	if (currentToken.type == tokBegin) fNode->appendChild( Block() ); // for followed by a block
	else fNode->appendChild( Statement() ); // while followed by single statement

	return fNode;
}
开发者ID:,项目名称:,代码行数:15,代码来源:

示例8: Print

TreeNode* Parser::Print()
{
	TreeNode* node = new TreeNode(currentToken, printNode);
	preservedToken = currentToken; // preserve token, else Match() will make sure it gets lost
	getToken();
	if (currentToken.type == tokEOL) return node; // print called without expressions
	node->appendChild( Expression() ); // first expression
	// following strings or expressions
	while (currentToken.type == tokComma)
	{
		getToken(); // the comma
		node->appendChild( Expression() );
	}
	matchToken(tokEOL);
	return node;
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例9: Term

TreeNode* Parser::Term()
{
	TreeNode* termNode = signedFactor();
	TreeNode* pos = termNode;
	TreeNode* left = NULL;
	TreeNode* right = NULL;

	while ( (currentToken.type == tokMul) || (currentToken.type == tokDev) || (currentToken.type == tokAnd) )
	{
		// while is is a multiplicative operator do...
		left = pos;
		pos = new TreeNode(currentToken, Unknown);
		pos->appendChild(left);

		switch (currentToken.type)
		{
			case tokMul:
				matchToken(tokMul);
				right = signedFactor();
				pos->setType(mulNode);
				break;

			case tokDev:
				matchToken(tokDev);
				right = signedFactor();
				pos->setType(divNode);
				break;

			case tokAnd:
				matchToken(tokAnd);
				right = signedFactor();
				pos->setType(andNode);
				break;

			default:
				Error(currentToken, i18n("Expected '*' or '/'"), 1030);
				getToken();
				return pos;
				break;
		}
		if (right != NULL) pos->appendChild(right);
		termNode = pos;
	}
	return termNode;
}
开发者ID:,项目名称:,代码行数:45,代码来源:

示例10: ExternalRun

TreeNode* Parser::ExternalRun()
{
	TreeNode* node = new TreeNode(currentToken, runNode);
	preservedToken = currentToken;
	getToken();
	node->appendChild( Expression() );
	// matchToken(tokEOL);  this command can return values so can be used as expression/parameter
	return node;
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例11: Return

TreeNode* Parser::Return()
{
	TreeNode* ret = new TreeNode(currentToken, returnNode);
	matchToken(tokReturn);

	ret->appendChild( Expression() );

	return ret;
}
开发者ID:,项目名称:,代码行数:9,代码来源:

示例12: signedFactor

TreeNode* Parser::signedFactor()
{
	// see if there is a tokPlus, tokMinus or tokNot infront of the factor
	TreeNode* node;
	switch (currentToken.type)
	{
		case tokPlus:
			matchToken(tokPlus);
			return Factor();
			break;

		case tokMinus:
			preservedToken = currentToken;
			matchToken(tokMinus);
			node = Factor();
			if (node->getType() == constantNode)
			{
				// in case of just a constant (-3) situation
				Value num = node->getValue();
				num.setNumber( -num.Number() );
				node->setValue(num);
				return node;
			}
			else
			{
				// in case of a variable or other situation (-a)
				TreeNode* minus = new TreeNode(preservedToken, minusNode);
				minus->appendChild(node);
				return minus;
			}
			break;

		case tokNot:
			preservedToken = currentToken;
			matchToken(tokNot);
			node = Factor();
			{ // extra scope needed to localize not_Node
				TreeNode* not_Node = new TreeNode(preservedToken, notNode);
				not_Node->appendChild(node);
				return not_Node;
			}
			break;

		default:
			// fall-through safety
			return Factor();
			break;
	}
}
开发者ID:,项目名称:,代码行数:49,代码来源:

示例13: Block

TreeNode* Parser::Block()
{
	TreeNode* block = new TreeNode(currentToken, blockNode, "block");

	while (currentToken.type == tokEOL) getToken(); // skip newlines
	matchToken(tokBegin);
	while (currentToken.type == tokEOL) getToken(); // skip newlines
	while ( (currentToken.type != tokEnd) && (currentToken.type != tokEOF) )
	{
		block->appendChild( Statement() );
		while (currentToken.type == tokEOL) getToken(); // blocks can have newlines between their statements
	}
	matchToken(tokEnd);
	return block;
}
开发者ID:,项目名称:,代码行数:15,代码来源:

示例14: Assignment

TreeNode* Parser::Assignment(Token t)
{
	TreeNode* node = new TreeNode(t, assignNode);
	matchToken(tokAssign); // match the '='

	// the child is the expression or RHV of assignment
	TreeNode* expr = NULL;
// 	if (currentToken.type == tokUnknown) expr = Other(); // in case of an functioncall
// 	else expr = Expression();               -------> fuctioncalls get caught in Expression() and co.
	
	expr = Expression();
	
	node->appendChild(expr);

	return node;
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例15: For

TreeNode* Parser::For()
{
	TreeNode* fNode = new TreeNode(currentToken, forNode);
	preservedToken = currentToken;
	matchToken(tokFor);
	fNode->appendChild( getId() ); // loop id
	matchToken(tokAssign);
	
	fNode->appendChild( Expression() ); // start value expression
	matchToken(tokTo);
	fNode->appendChild( Expression() ); // stop value expression

	if (currentToken.type == tokStep)
	{
		matchToken(tokStep);
		fNode->appendChild( Expression() ); //step expression
	}

	while (currentToken.type == tokEOL) getToken(); // newlines are allowed
	if (currentToken.type == tokBegin) fNode->appendChild( Block() ); // for followed by a block
	else fNode->appendChild( Statement() ); // while followed by single statement

	return fNode;
}
开发者ID:,项目名称:,代码行数:24,代码来源:


注:本文中的TreeNode::appendChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。