コード例 #1
0
 /**
  * @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;
 }
コード例 #2
0
 /**
  * @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;
 }