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


C++ Expression::ParseExpression方法代码示例

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


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

示例1: HandleConditional

/// For if- and elsif- statements.
void Script::HandleConditional(String line)
{
	// Remove first part until (
	int index = line.Find('(');
	line = line.Part(index);
	/// Use expressions from the MathLib. First parse for functions to provide their values? Or...
	Expression exp;
	List<Variable> allVars = GameVars.GetAllExpressionVariables() + variables;
	exp.functionEvaluators = functionEvaluators; // Set evaluators.
	bool parseOK = exp.ParseExpression(line);
	if (!parseOK)
	{
		std::cout<<"\nParse error in expression "<<line;
		return;
	}
	ExpressionResult res = exp.Evaluate(allVars);
	bool statementTrue = res.GetBool();
	/// If statement is true, sign this row as finished.
	if (statementTrue)
	{
		// Set line finished to true so the actual content will be processed.
		lineFinished = true;
		// Set if-Processed to true so that no elsif- or else- clause will be handled.
		ScriptLevel & latest = stack.Last();
		latest.evaluatedAtLine = currentLine;
	}
	else 
	{
		// Check stuff.
		ScriptLevel & sl = stack.Last();
		int newRow = -1;
		int ifStack = 0;
		// If the statement is not true, find an else or endif block..!
		for (int i = currentLine+1; i < lines.Size(); ++i)
		{
			String l = lines[i];
			if (sl.type == ScriptLevel::WHILE_LOOP)
			{
				if (l.Contains("endwhile"))
				{
					// Jump to next after, as regular stopping on endwhile will reboot the loop
					newRow = i + 1;
					stack.RemoveLast();
					break; 
				}
			}
			if (sl.type == ScriptLevel::IF_CLAUSE)
			{
				if (l.Contains("elsif") || l.Contains("else") || l.Contains("endif"))
				{
					if (ifStack == 0)
					{
						newRow = i; 
						break;
					}
					if (l.Contains("endif"))
						--ifStack;
				}
				else if (l.Contains("if"))
					++ifStack;
			}
		}
		assert(newRow > 0);
		// Process it next iteration.
		currentLine = newRow;
		lineProcessed = false;
		lineFinished = false;
		return;

	}
	if (lineFinished == false)
		assert(false && "Line not finished? Something is missing in the if/else/endif block!");	
}
开发者ID:erenik,项目名称:engine,代码行数:74,代码来源:Script.cpp

示例2: EvaluateLine


//.........这里部分代码省略.........
	else if (line.Contains("endif"))
	{
		ScriptLevel sl = stack.Last();
		assert(sl.type == ScriptLevel::IF_CLAUSE);
		stack.RemoveLast();
		lineFinished = true;
	}
	else if (line.Contains("endwhile"))
	{
		// Go to start!
		ScriptLevel sl = stack.Last();
		assert(sl.type == ScriptLevel::WHILE_LOOP);
		currentLine = sl.evaluatedAtLine;
		String startLine = lines[currentLine];
		HandleConditional(startLine);
//		lineFinished = true;
		// Evaluate?
//		stack.RemoveLast();
	}
	else if (line.Contains("while"))
	{
		stack.AddItem(ScriptLevel(ScriptLevel::WHILE_LOOP, currentLine));
		HandleConditional(line);
	}
/*	else if (line.Contains("CreateInt")){
		List<String> tokens = line.Tokenize(" \t");
		String varName = tokens[1];
		int initialValue = 0;
		if (tokens.Size() >= 3)
			initialValue = tokens[2].ParseInt();
		if (!GameVars.Get(varName)){
			GameVars.CreateInt(varName, initialValue);
		}
		lineFinished = true;
	}
	/*
	else if (line.Contains("SetInt ")){
		List<String> tokens = line.Tokenize(" \t");
		String varName = tokens[1];
		int value = tokens[2].ParseInt();
		GameVars.SetInt(varName, value);
		lineFinished = true;
	}*/
	else if (line.Contains("Repeatable")){
		/// Flag the event as repeatable.
		repeatable = true;
		lineFinished = true;
	}
	// Consider just making an else-clause for all remaining events to be processed by the specific game instead?
	else if (
		line.Contains("SpawnEntity") ||
		line.Contains("OnApproach") ||
		line.Contains("OnInteract") ||
		line.Contains("DisableMovement") ||
		line.Contains("EnableMovement") ||
		line.Contains("Zone(") ||
		line.Contains("PlacePlayer(") ||
		line.Contains("TrackPlayer")
		)
	{
		Message * message = new Message(line);
		/// Set this event as
		message->scriptOrigin = this;
		MesMan.QueueMessage(message);
		/// Instant thingies.
		lineFinished = true;
	}
	else {
		/// Try evaluate it as an expression.
		Expression exp;
		List<Variable> allVars = GameVars.GetAllExpressionVariables() + variables;
		exp.functionEvaluators = functionEvaluators; // Set evaluators.
		bool parseOK = exp.ParseExpression(line);
		if (line.Contains("SetMovementPattern"))
			int p = 4;;
		if (parseOK)
		{
			ExpressionResult res = exp.Evaluate(allVars);
			/// Continue until it returns true! o.o
			if (res.type != DataType::NO_TYPE)
			{
				if (res.GetBool() == true)
				{
					lineFinished = true;
					return;
				}
			}
		}


//		std::cout<<"\nUndefined event command: "<<line;
//		std::cout<<"\nPassing it as a custom command to the game states for further processing.";
		Message * message = new Message(line);
		/// Set this event as source of it.
		message->scriptOrigin = this;
		MesMan.QueueMessage(message);
		lineFinished = true;
	//	assert(false && "Undefined event command!");
	};
}
开发者ID:erenik,项目名称:engine,代码行数:101,代码来源:Script.cpp


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