/** * @param \Helstern\Nomsky\Grammar\Symbol\SymbolSet $set * @param NormalizedProduction $production * @param \Helstern\Nomsky\GrammarAnalysis\ParseSets\ParseSets $followSets * @param \Helstern\Nomsky\GrammarAnalysis\ParseSets\ParseSets $firstSets * * @return bool */ public function processProduction(SymbolSet $set, NormalizedProduction $production, ParseSets $followSets, ParseSets $firstSets) { $rhs = $production->getRightHandSide(); $epsilonAdded = $this->firstSetCalculator->processSymbolList($set, $rhs, $firstSets); if ($epsilonAdded) { $lhs = $production->getLeftHandSide(); $otherSet = $followSets->getTerminalSet($lhs); $set->addAll($otherSet); } return $epsilonAdded; }
/** * @param NormalizedProduction $production * @param SymbolSet $alreadyAdded * * @return bool */ private function indirectlyGeneratesEpsilon(NormalizedProduction $production, SymbolSet $alreadyAdded) { $rhsItems = $production->getRightHandSide(); /** @var Symbol $item */ $item = reset($rhsItems); $answer = $alreadyAdded->contains($item); for (next($rhsItems); $answer && !is_null(key($rhsItems)); next($rhsItems)) { $item = current($rhsItems); $answer = $answer && $alreadyAdded->contains($item); } $answer = is_null(key($rhsItems)) && $answer; return $answer; }