本文整理汇总了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();
}