本文整理汇总了C++中BitSet::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ BitSet::isEmpty方法的具体用法?C++ BitSet::isEmpty怎么用?C++ BitSet::isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitSet
的用法示例。
在下文中一共展示了BitSet::isEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: diff
void Grammar::findFirst1Sets() {
findEpsilonSymbols();
const int n = getProductionCount();
bool stable;
do {
stable = true;
for(int p = 0; p < n; p++) {
const Production &prod = m_productions[p];
const int length = prod.getLength();
GrammarSymbol &ls = getSymbol(prod.m_leftSide);
for(int k = 0; k < length; k++) {
const int sk = prod.m_rightSide[k];
if(isTerminal(sk)) {
if(!ls.m_first1.contains(sk)) {
ls.m_first1.add(sk);
// _tprintf(_T("first1(%s) : "), ls.m_name.cstr()); dump(ls.m_first1); printf(_T(")\n");
stable = false;
}
break;
}
else { // nonterminal
const GrammarSymbol &nt = getSymbol(sk);
const BitSet diff(nt.m_first1 - ls.m_first1);
if(!diff.isEmpty()) {
ls.m_first1 += nt.m_first1;
// printf(_T(")first1(%s) : ", ls.m_name.cstr()); dump(ls.m_first1); printf(_T(")\n");
stable = false;
}
if(!nt.m_deriveEpsilon) {
break;
}
}
}
}
/*
gotoxy(0, 0);
for(long s = getTerminalCount(); s < getSymbolCount(); s++) {
GrammarSymbol &nonTerm = getSymbol(s);
_tprintf(_T("first(%-10s):"), nonTerm.m_name.cstr());
dump(nonTerm.m_first1);
_tprintf(_T("\n"));
}
pause();
*/
} while(!stable);
}
示例2: checkStateIsConsistent
void Grammar::checkStateIsConsistent(const LR1State &state, StateResult &result) {
BitSet symbolsDone(getSymbolCount());
const int itemCount = (int)state.m_items.size();
for(int i = 0; i < itemCount; i++) {
const LR1Item &item = state.m_items[i];
if(isShiftItem(item)) {
const int t = getShiftSymbol(item);
if(symbolsDone.contains(t)) {
continue;
}
for(int j = 0; j < itemCount; j++) {
if(j == i) {
continue;
}
const LR1Item &item1 = state.m_items[j];
if(isReduceItem(item1) && item1.m_la.contains(t)) {
const GrammarSymbol &terminal = getSymbol(t);
switch(resolveShiftReduceConflict(terminal, item1)) {
case CONFLICT_NOT_RESOLVED:
m_SRconflicts++;
result.m_errors.add(format(_T("Shift/reduce conflict. Shift or reduce by prod %-3d (prec=%d) on '%s' (prec=%d, %s).")
,item1.m_prod
,getProduction(item1).m_precedence
,terminal.m_name.cstr()
,terminal.m_precedence
,terminal.getTypeString()));
break;
case CHOOSE_SHIFT:
result.m_actions.add(ParserAction(t, item.getSuccessor()));
symbolsDone += t;
result.m_warnings.add(format(_T("Shift/reduce conflict on %s (prec=%d, %s). Choose shift instead of reduce by prod %d (prec=%d).")
,terminal.m_name.cstr()
,terminal.m_precedence
,terminal.getTypeString()
,item1.m_prod
,getProduction(item1).m_precedence));
m_warningCount++;
break;
case CHOOSE_REDUCE:
result.m_actions.add(ParserAction(t, -item1.m_prod));
symbolsDone += t;
result.m_warnings.add(format(_T("Shift/reduce conflict on %s (prec=%d, %s). Choose reduce by prod %d (prec=%d).")
,terminal.m_name.cstr()
,terminal.m_precedence
,terminal.getTypeString()
,item1.m_prod
,getProduction(item1).m_precedence));
m_warningCount++;
break;
}
}
}
if(!symbolsDone.contains(t)) {
if(item.m_succ >= 0) {
result.m_actions.add(ParserAction(t, item.getSuccessor()));
}
symbolsDone += t;
continue;
}
}
}
for(int i = 0; i < itemCount; i++) {
const LR1Item &itemi = state.m_items[i];
if(isReduceItem(itemi)) {
BitSet tokensReducedByOtherItems(getTerminalCount());
if(isAcceptItem(itemi)) { // check if this is start -> S . [EOI]
result.m_actions.add(ParserAction(0, 0));
if(symbolsDone.contains(0)) {
throwException(_T("Token EOI already done in state %d while generating Acceptitem"), state.m_index);
}
symbolsDone += 0;
continue;
}
for(int j = 0; j < itemCount; j++) {
if(j == i) {
continue;
}
const LR1Item &itemj = state.m_items[j];
if(isReduceItem(itemj)) {
const BitSet intersection(itemi.m_la & itemj.m_la);
if(!intersection.isEmpty()) {
if(itemj.m_prod < itemi.m_prod) {
tokensReducedByOtherItems += intersection;
result.m_warnings.add(format(_T("Reduce/reduce conflict on %s between prod %d and prod %d. Choose prod %d.")
,symbolSetToString(intersection).cstr()
,itemj.m_prod
,itemi.m_prod
,itemj.m_prod));
m_warningCount++;
}
}
}
}
BitSet itemTokens(itemi.m_la - tokensReducedByOtherItems);
for(Iterator<size_t> it = itemTokens.getIterator(); it.hasNext(); ) {
const unsigned short t = (unsigned short)it.next();
if(!symbolsDone.contains(t)) {
result.m_actions.add(ParserAction(t, -itemi.m_prod));
//.........这里部分代码省略.........