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; }
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; } }