예제 #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 SymbolSet $set
  * @param NormalizedProduction $production
  *
  * @return bool
  */
 public function processProduction(SymbolSet $set, NormalizedProduction $production)
 {
     $nonTerminal = $production->getLeftHandSide();
     if ($set->contains($nonTerminal)) {
         return false;
     }
     //directly generates epsilon (rhs is epsilon)
     if ($this->directlyGeneratesEpsilon($production)) {
         $set->add($nonTerminal);
         return true;
     }
     //indirectly generates epsilon (all from rhs must generate epsilon)
     if ($this->indirectlyGeneratesEpsilon($production, $set)) {
         $set->add($nonTerminal);
         return true;
     }
     return false;
 }