本文整理汇总了C++中ParseNode::getTokenText方法的典型用法代码示例。如果您正苦于以下问题:C++ ParseNode::getTokenText方法的具体用法?C++ ParseNode::getTokenText怎么用?C++ ParseNode::getTokenText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseNode
的用法示例。
在下文中一共展示了ParseNode::getTokenText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doParse
// pre: root != NULL
void doParse(ParseNode *root, std::string inFileName, std::string outBaseName)
{
std::map<std::string, std::string> firstManualToken;
FaSymbolTable symTab;
FaRuleIr ruleIr(&symTab);
// Iterate thru children of start symbol.
for(ParseNode::iterator_type i = root->begin(); i != root->end(); ++i)
{
ParseNode *statement = *i;
ParseNode *statementHead = *statement->begin();
std::string statementHeadText = statementHead->getTokenText();
if(statementHeadText.empty())
{
// name "::=" alternate { '|' alternate } ';'
// name ::= IDENT | "start" ;
///std::cout << "[name]" << std::endl;
std::string ruleName = (*statementHead->begin())->getTokenText();
ParseNode::iterator_type j = statement->begin();
++j; // skip ruleName
++j; // skip "::="
for(;;)
{
ParseNode *alternate = *j;
parseAlternate(symTab, ruleIr, alternate, ruleName);
++j; // skip alternate
if((*j)->getTokenText() != "|")
break; // found ';' at end
++j; // skip '|'
}
}
else
if(statementHeadText == "token")
{
for(ParseNode::iterator_type j = ++statement->begin(); j != statement->end(); ++j)
{
std::string s = (*j)->getTokenText();
if(s == ";")
break;
ruleIr.addToken(s);
}
}
else
if(statementHeadText == "keyword")
{
std::string s1 = (*(++statement->begin()))->getTokenText();
std::string s2 = (*(++(++statement->begin())))->getTokenText();
ruleIr.addKeyword(s1, s2);
}
else
if(statementHeadText == "copyright")
{
ruleIr.setCopyright(unquote((*(++statement->begin()))->getTokenText()));
}
else
if(statementHeadText == "prefix")
{
ruleIr.setPrefix(unquote((*(++statement->begin()))->getTokenText()));
}
else
if(statementHeadText == "manual")
{
ParseNode::iterator_type j = ++statement->begin();
std::string s0 = (*j)->getTokenText();
++j;
std::string s1 = unquote((*j)->getTokenText());
++j;
ruleIr.addToken(s0);
firstManualToken[s0] = s1;
if(s1.empty() || (s1.size() & 1) != 0)
{
std::string msg = "invalid manual token definition (both string literals must be nonempty and even in length)";
throw ParseSpecificError((*i)->getLine(), (*i)->getFile(), msg);
}
}
}
std::string err = ruleIr.convertGrammar();
if(!err.empty())
{
std::cerr << "error: " << inFileName << ": " << err << std::endl;
throw ParseError();
}
std::string fn1 = "out_" + outBaseName + "_parser.h";
std::string fn2 = "out_" + outBaseName + "_header.h";
std::string fn3 = "out_" + outBaseName + "_lexer.h";
std::ofstream fo1(fn1.c_str());
ruleIr.writeParser(fo1, fn1);
std::ofstream fo2(fn2.c_str());
ruleIr.writeHeader(fo2, fn2);
std::ofstream fo3(fn3.c_str());
ruleIr.writeLexer(fo3, fn3, firstManualToken);
}