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


C++ Evaluator::exec方法代码示例

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


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

示例1: lex

int
main(int argc, char* argv[])
{
    init_colors();

    // Prepare the symbol table.
    Symbol_table syms;
    init_symbols(syms);

    Module_decl mod;

    // Prepare the input buffer.
    File src = argv[1];
    Input_buffer in = src;

    try {
        // Create the token stream over. This will be populated
        // by the lexer.
        Token_stream ts;

        // Build and run the lexer.
        Lexer lex(syms, in);
        if (!lex.lex(ts))
            return -1;

        // Build and run the parser. The location map
        // is used to save source locations, which are
        // used to diagnose elaboration errors.
        Location_map locs;
        Parser parse(syms, ts, locs);
        if (!parse.module(&mod))
            return -1;

        // Perform semantic analysis.
        //
        // TODO: Implement a parse-only phase.
        Elaborator elab(locs, syms);
        elab.elaborate(&mod);

        // Find an entry point for evaluation.
        //
        // TODO: The resolution of main is a little artificial.
        // Also, we need to ensure that static initializers
        // are evaluated prior to entering main.
        //
        // TODO: Actually pass command line arguments to main.
        if (elab.main) {
            Evaluator ev;
            Value v = ev.exec(elab.main);
            std::cout << "result: " << v << '\n';
        } else {
            std::cout << "no main\n";
        }
    }

    // Diagnose uncaught translation errors and exit
    // gracefully. All other uncaught exceptions are
    // ICEs and we want those to fail noisily. Note
    // that re-throwing does not re-establish the
    // origin of the error for the purpose of debugging.
    catch (Translation_error& err) {
        diagnose(err);
        return -1;
    }

    // FIXME: Do something with the module.
}
开发者ID:cjb129,项目名称:beekar,代码行数:67,代码来源:interpreter.cpp


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