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


C++ Lexer::build_grammar方法代码示例

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


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

示例1: build_grammar

size_t Capture::build_grammar(string* rule, size_t location)
{
        this->location = location;
        int depth_cnt = 0;
        int cnt = 1;
        for (string::iterator it = rule->begin(); it != rule->end();
                        ++it, cnt++) {
                char c = *it;
                switch (c) {
                case '(':
                        if (depth_cnt++ != 0) {
                                this->text.push_back(c);
                        }
                        break;
                case ')':
                        depth_cnt--;
                        if (depth_cnt > 0) {
                                this->text.push_back(c);
                        } else if (depth_cnt < 0) {
                                cerr << "Found ')' at char " << location
                                << " but was not matched!" << endl;
                                exit(-4);
                        } else {
                                goto end_of_loop;
                        }
                        break;
                default:
                        if (depth_cnt != 0) {
                                this->text.push_back(c);
                        }
                        break;

                }
        }
        cerr << "Expected ')' but was not found!" << endl;
        cerr << "( at " << location << " was not matched!" << endl;
        exit(-2);

        end_of_loop:

        this->str_length = cnt;
        if (verbose) {
                /* Dump the parsed input */
                cout << "Captured: " << this->text << endl;
        }

        Lexer* nodes = new Lexer(location);
        nodes->build_grammar(&this->text);

        Token* symbols = nodes->get_tokens()->omit_starter();

        if (symbols != NULL) {
                this->setRight(symbols);
                symbols->setParent(this);
        } else {
                cerr << "Error at " << location << endl;
        }

        /* Make sure there are no undefined pointers after deleting nodes */
        symbols->set_parser(this->parser);

        delete nodes;
        return this->length();
}
开发者ID:bemk,项目名称:Automaton,代码行数:64,代码来源:Capture.cpp


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