本文整理汇总了C++中Expression::execute方法的典型用法代码示例。如果您正苦于以下问题:C++ Expression::execute方法的具体用法?C++ Expression::execute怎么用?C++ Expression::execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression::execute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main ()
{
ProgramMemory::InitProgramMemory();
Tokenizer tokenizer (cin);
Expression *program = Parser::parse (tokenizer);
Value* programResult = program->execute();
ProgramMemory::DeleteProgramMemory();
Expression::printTree (program,cerr);
delete programResult;
delete program;
}
示例2: interpretCommand
CommandResult ExpressionInterpreter::interpretCommand(string userInput)
{
CommandResult result = CommandSuccess;
string text;
stringstream ss;
ss << userInput;
ExpressionList currentState;
currentState.push_back(mpRoot);
ExpressionList nextState;
while (result == CommandSuccess && !ss.eof())
{
ss >> text;
transform(text.begin(), text.end(), text.begin(), ::tolower);
ExpressionList::const_iterator iter = currentState.begin();
ExpressionList::const_iterator end = currentState.end();
for (; iter != end; ++iter)
{
Expression* expr = *iter;
ExpressionList exprNextList = expr->getNextExpressionClosure(text);
nextState.splice(nextState.end(), exprNextList);
}
if (nextState.size() > 0)
{
currentState = nextState;
nextState.clear();
}
else
{
mErrorText = "'" + text + "' not recognized.";
result = CommandInvalid;
}
}
//remove impossible expressions in the final state before checking for ambiguity
nextState.clear();
ExpressionList::const_iterator iter = currentState.begin();
ExpressionList::const_iterator end = currentState.end();
for (; iter != end; ++iter)
{
Expression* expr = *iter;
if (expr->isExecutable())
{
nextState.push_back(expr);
}
else
{
ExpressionList children = expr->getNextExpressions();
bool flag = false;
ExpressionList::const_iterator iter = children.begin();
ExpressionList::const_iterator end = children.end();
for (; iter != end; ++iter)
{
if ((*iter)->getName()[0] == '[')
{
flag = true;
}
}
if (flag || children.size() == 0)
{
nextState.push_back(expr);
}
}
}
currentState = nextState;
if (currentState.size() != 1)
{
mErrorText = "'" + text + "' ambiguous or incomplete.";
result = CommandInvalid;
}
//run command if executable and non-ambiguous
if (result == CommandSuccess)
{
Expression* expr = *(currentState.begin());
ExpressionList executables = expr->getClosureExecutables(false);
if (executables.size() == 1)
{
ilmErrorTypes initResult = ilm_init();
if (ILM_SUCCESS != initResult)
{
mErrorText = ILM_ERROR_STRING(initResult);
result = CommandExecutionFailed;
}
else
{
Expression* exec = executables.front();
exec->execute();
ilm_commitChanges();
ilm_destroy();
}
//.........这里部分代码省略.........