本文整理汇总了C++中Interpreter::execute方法的典型用法代码示例。如果您正苦于以下问题:C++ Interpreter::execute方法的具体用法?C++ Interpreter::execute怎么用?C++ Interpreter::execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter
的用法示例。
在下文中一共展示了Interpreter::execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
bool heatSetpoint::operator()(const block_ptr &b, Interpreter &interp) {
float sp = (b->args()[0].find("block:") != std::string::npos) ?
interp.execute(b->blockArgs()[stoi(b->args()[0].substr(b->args()[0].find(":") + 1))]) :
stof(b->args()[0]);
float db = (b->args()[1].find("block:") != std::string::npos) ?
interp.execute(b->blockArgs()[stoi(b->args()[1].substr(b->args()[1].find(":") + 1))]) :
stof(b->args()[1]);
float in = (b->args()[2].find("block:") != std::string::npos) ?
interp.execute(b->blockArgs()[stoi(b->args()[2].substr(b->args()[2].find(":") + 1))]) :
stof(b->args()[2]);
LOG(Log::DEBUGGING, "heatSetpoint");
if (heating && (in > (sp + db))) {
heating = false;
} else if (!heating && (in < (sp - db))) {
heating = true;
}
return heating;
}
示例2: executeConsoleScript
void executeConsoleScript()
{
interpreter.execute(consoleText->getString());
}
示例3: main
int main(int argc, char *argv[])
{
using namespace std;
bool print_tokens = false, print_ast = false, no_run = false;
// Refer whether tokens and ast need to be printed.
int name_count = 0;
// Count the filename inputed.
string filename;
// Save the name of file.
string raw;
if (argc < 2)
{
// A correct call of rune must given 2 or more args;
show_help();
return -2;
}
else
{
for (int i = 1; i < argc; ++i)
{
if (argv[i][0] == '-')
{
switch(argv[i][1])
{
case 't':
print_tokens = true;
break;
case 'a':
print_ast = true;
break;
case 'n':
no_run = true;
break;
default:
cout << "unrecognized command line option \'"
<< argv[i] << '\'';
show_help();
return -2;
}
}
else
{
filename = argv[i];
name_count++;
}
}
if (name_count != 1)
{
// if more than 1 filenames were inputed, show help and exit.
show_help();
return -2;
}
}
raw = read_all_from_file(filename);
if (raw.size() == 0)
{
// **There is a pitfall.
// **I'm not sure how to get known the existance of file.
// **So, deal as same when file not exist and empty.
cout << "file not exist or nothing contained in file.";
return -3;
}
try
{
Preprocessor pre;
vector<string> lines = pre.preprocess(raw);
// Raw string preprocessed to decommented lines.
Scanner scn;
vector<Token> tokens = scn.scan(lines);
// Scan the lines to a vector of Tokens.
// Token is defined in "tokenEnum.h".
if (print_tokens)
{
show_tokens(tokens);
}
// print Tokens if has option "-tokens".
Parser psr;
auto ast = psr.parse(tokens);
// Parse the Tokens to an Abstract Syntax Tree.
// AST is defined in "syntexTreeEnum.h".
if (print_ast)
{
cout << "SYNTAX TREE:\n";
psr.show_tree(ast);
}
// print AST if has option "-ast".
if (!no_run)
{
Interpreter itp;
itp.execute(ast);
// Interprete the AST.
}
}
catch (string msg)
{
cout << msg << endl;
return -1;
// print error message.
}
//.........这里部分代码省略.........