bool dDeterministicFiniteAutonata::CompareSets (dList<dAutomataState*>& setA, dTree<dAutomataState*,dAutomataState*>& setB) const
{
	if (setA.GetCount() == setB.GetCount()) {
		for (dList<dAutomataState*>::dListNode* node = setA.GetFirst(); node; node = node->GetNext()) {
			if (!setB.Find(node->GetInfo())) {
				return false;
			}
		}
		return true;
	}
	return false;
}
Exemplo n.º 2
0
void dParserCompiler::First (
	const dList<dCRCTYPE>& symbolSet, 
	const dTree<dTokenInfo, dCRCTYPE>& symbolList, 
	const dTree<dList<void*>, dCRCTYPE>& ruleMap,
	dTree<int, dCRCTYPE>& firstSetOut) const
{
	if (symbolSet.GetCount() > 1) {

		dList<dCRCTYPE>::dListNode* node = symbolSet.GetFirst();
		bool deriveEmpty = true;
		while ((deriveEmpty) && node) {
			dCRCTYPE symbol = node->GetInfo();
			node = node->GetNext();

			dTree<int, dCRCTYPE> tmpFirst;
			dTree<int, dCRCTYPE> symbolListMark; 
			First (symbol, symbolListMark, symbolList, ruleMap, tmpFirst);
			dTree<int, dCRCTYPE>::Iterator iter (tmpFirst);
			deriveEmpty = false;  
			for (iter.Begin(); iter; iter ++) {
				dCRCTYPE symbol = iter.GetKey();
				if (symbol == 0) {
					deriveEmpty = true;  
				} else {
					firstSetOut.Insert(0, symbol);
				}
			}
		}
		if (deriveEmpty) {
			firstSetOut.Insert(0, 0);
		}

	} else  {
		dCRCTYPE symbol = symbolSet.GetFirst()->GetInfo();
		dTree<int, dCRCTYPE> symbolListMark; 
		First (symbol, symbolListMark, symbolList, ruleMap, firstSetOut);
	}
}