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


C++ Interpreter::execute方法代码示例

本文整理汇总了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;
	}
开发者ID:aaronh82,项目名称:Omniscript,代码行数:21,代码来源:HVAC.cpp

示例2: executeConsoleScript

void executeConsoleScript()
{
	interpreter.execute(consoleText->getString());
}
开发者ID:tolhc1234,项目名称:openglengine,代码行数:4,代码来源:Interpreter.cpp

示例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.
    }
//.........这里部分代码省略.........
开发者ID:Robert-Lu,项目名称:Rune-Interpreter,代码行数:101,代码来源:RuneInterpreter.cpp


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