本文整理汇总了C++中Grammar::isTerminal方法的典型用法代码示例。如果您正苦于以下问题:C++ Grammar::isTerminal方法的具体用法?C++ Grammar::isTerminal怎么用?C++ Grammar::isTerminal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grammar
的用法示例。
在下文中一共展示了Grammar::isTerminal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
void DotGraph::operator () (Automaton *aut)
{
Grammar *g = aut->_M_grammar;
out << "digraph {" << endl << endl;
out << "subgraph Includes {" << endl;
for (Automaton::IncludesGraph::iterator incl = Automaton::IncludesGraph::begin_nodes ();
incl != Automaton::IncludesGraph::end_nodes (); ++incl)
{
for (Automaton::IncludesGraph::edge_iterator edge = incl->begin (); edge != incl->end (); ++edge)
{
out << "\t\"(" << aut->id (incl->data.state) << ", " << incl->data.nt << ")\"";
out << "\t->\t";
out << "\"(" << aut->id ((*edge)->data.state) << ", " << (*edge)->data.nt << ")\"\t";
out << "[label=\"" << incl->data.state->follows [incl->data.nt] << "\"]";
out << endl;
}
}
out << "}" << endl << endl;
out << "subgraph LRA {" << endl;
//out << "node [shape=record];" << endl << endl;
for (StatePointer q = aut->states.begin (); q != aut->states.end (); ++q)
{
int state = aut->id (q);
out << "\t" << state << "\t[shape=record,label=\"{";
out << "<0> State " << state;
int index = 1;
for (ItemPointer item = q->kernel.begin (); item != q->kernel.end (); ++item)
out << "| <" << index++ << "> " << *item;
out << "}\"]" << endl;
for (Bundle::iterator a = q->bundle.begin (); a != q->bundle.end (); ++a)
{
const char *clr = g->isTerminal (a.key ()) ? "blue" : "red";
out << "\t" << state << "\t->\t" << aut->id (*a) << "\t[color=\"" << clr << "\",label=\"" << a.key () << "\"]" << endl;
}
out << endl;
}
out << "}" << endl;
out << endl << endl << "}" << endl;
}
示例2: operator
void ParseTable::operator () (Automaton *aut)
{
Grammar *g = aut->_M_grammar;
int rindex = 1;
for (RulePointer rule = g->rules.begin (); rule != g->rules.end (); ++rule)
out << rindex++ << ")\t" << *rule << endl;
out << endl << endl;
int index = 0;
for (StatePointer state = aut->states.begin (); state != aut->states.end (); ++state)
{
out << "state " << index++ << endl << endl;
for (ItemPointer item = state->kernel.begin (); item != state->kernel.end (); ++item)
{
out << " * " << *item;
if (item->dot == item->end_rhs ())
out << " " << aut->lookaheads [item];
out << endl;
}
bool first = true;
for (Bundle::iterator arrow = state->bundle.begin (); arrow != state->bundle.end (); ++arrow)
{
if (! g->isTerminal (arrow.key ()))
continue;
if (first)
out << endl;
first = false;
out << " " << *arrow.key () << " shift, and go to state " << std::distance (aut->states.begin (), *arrow) << endl;
}
first = true;
for (ItemPointer item = state->closure.begin (); item != state->closure.end (); ++item)
{
if (item->dot != item->end_rhs () || item->rule == state->defaultReduce)
continue;
if (first)
out << endl;
first = false;
foreach (Name la, aut->lookaheads.value (item))
out << " " << *la << " reduce using rule " << aut->id (item->rule) << " (" << *item->rule->lhs << ")" << endl;
}
first = true;
for (Bundle::iterator arrow = state->bundle.begin (); arrow != state->bundle.end (); ++arrow)
{
if (! g->isNonTerminal (arrow.key ()))
continue;
if (first)
out << endl;
first = false;
out << " " << *arrow.key () << " go to state " << std::distance (aut->states.begin (), *arrow) << endl;
}
if (state->defaultReduce != g->rules.end ())
{
out << endl
<< " $default reduce using rule " << aut->id (state->defaultReduce) << " (" << *state->defaultReduce->lhs << ")" << endl;
}
out << endl;
}
}