// Rule::Context void Rule::Context::clear() { for (set<EpsilonNFA_State*>::iterator i = epsilonNFA_States.begin(), m = epsilonNFA_States.end(); i != m; ++i) { destruct(*i, has_destruct(*(*i))); EpsilonNFA_State_Alloc::deallocate(*i); } epsilonNFA_States.clear(); for (set<DFA_State*>::iterator i = dfa_States.begin(), m = dfa_States.end(); i != m; ++i) { destruct(*i, has_destruct(*(*i))); DFA_State_Alloc::deallocate(*i); } dfa_States.clear(); }
bool LALR1::make(ostream& errStream) { vector<LALR1Production> v; v.push_back(inputProductions[begin][0]); pStart = closure(v); pStart->idx = Item::inc(); context.states.insert(pStart); items.push_back(pStart); queue<Item*> q; q.push(pStart); vector<Item*> changes; bool bContinue = false; while (!q.empty()) { Item* pItem = q.front(); vector<Production::Item> s; symbols(pItem, s); select_into(s, vts, [](const Production::Item& i) { return i.isTermainalSymbol(); }, [](vector<Production::Item>& v, const Production::Item& i) { v.push_back_unique(i); }); select_into(s, vns, [](const Production::Item& i) { return i.isNoTerminalSymbol(); }, [](vector<Production::Item>& v, const Production::Item& i) { v.push_back_unique(i); }); for (vector<Production::Item>::const_iterator i = s.begin(), m = s.end(); i != m; ++i) { Item* pNewItem = NULL; if (go(pItem, *i, pNewItem)) { long n = itemIndex(pNewItem); if (n == -1) { pNewItem->idx = Item::inc(); q.push(pNewItem); items.push_back(pNewItem); context.states.insert(pNewItem); } else { items[n]->mergeWildCards(pNewItem, bContinue); changes.push_back_unique(items[n]); destruct(pNewItem, has_destruct(*pNewItem)); Item_Alloc::deallocate(pNewItem); } edges[pItem].push_back_unique(Edge(pItem, n == -1 ? pNewItem : items[n], *i)); } } q.pop(); } while (bContinue) { vector<Item*> v; v.reserve(changes.size()); bContinue = false; for (vector<Item*>::const_iterator i = changes.begin(), m = changes.end(); i != m; ++i) { vector<Production::Item> s; symbols(*i, s); for (vector<Production::Item>::const_iterator j = s.begin(), n = s.end(); j != n; ++j) { Item* pNewItem = NULL; if (go(*i, *j, pNewItem)) { long n = itemIndex(pNewItem); if (n == -1) throw error<const char*>("unknown item", __FILE__, __LINE__); else { items[n]->mergeWildCards(pNewItem, bContinue); v.push_back_unique(items[n]); destruct(pNewItem, has_destruct(*pNewItem)); Item_Alloc::deallocate(pNewItem); } } } } changes = v; } sort(vts.begin(), vts.end()); sort(vns.begin(), vns.end()); return buildParserTable(errStream); }