public function matchSymbol(Symbol $symbol)
 {
     $matches = $this->predicate->matchSymbol($symbol);
     if ($matches) {
         $this->matchCount++;
     }
     return $matches;
 }
 /**
  * @param Symbol $symbol
  * @return bool
  */
 protected function collectSymbol(Symbol $symbol)
 {
     if ($this->symbolPredicate->matchSymbol($symbol)) {
         $this->collectedSymbols[] = $symbol;
         return true;
     }
     return false;
 }
Пример #3
0
 /**
  * @param SymbolSet $otherSet
  * @param SymbolPredicate $acceptPredicate
  * @return bool
  */
 public function addSome(SymbolSet $otherSet, SymbolPredicate $acceptPredicate)
 {
     $newSymbolsAdded = false;
     foreach ($otherSet as $otherSymbol) {
         if ($acceptPredicate->matchSymbol($otherSymbol)) {
             $newSymbolsAdded |= $this->add($otherSymbol);
         }
     }
     return $newSymbolsAdded;
 }
Пример #4
0
 /**
  * @param Symbol $nonTerminal
  * @param SymbolPredicate $acceptPredicate
  * @return ArraySet
  */
 public function filterTerminalSet(Symbol $nonTerminal, SymbolPredicate $acceptPredicate)
 {
     $terminalSetIterator = $this->getTerminalSetIterator($nonTerminal);
     $filtered = new ArraySet();
     while ($terminalSetIterator->valid()) {
         $terminal = $terminalSetIterator->current();
         $terminalSetIterator->next();
         if ($acceptPredicate->matchSymbol($terminal)) {
             $filtered->add($terminal);
         }
     }
     return $filtered;
 }
Пример #5
0
 /**
  * @param \Helstern\Nomsky\Grammar\Symbol\Predicate\SymbolPredicate $predicate
  *
  * @return Symbol|null
  */
 public function findFirst(SymbolPredicate $predicate)
 {
     $found = null;
     foreach ($this->rhs as $symbol) {
         if ($predicate->matchSymbol($symbol)) {
             $found = $symbol;
         }
     }
     return $found;
 }
 /**
  * @param Symbol $symbol
  * @return mixed
  */
 public function matchSymbol(Symbol $symbol)
 {
     return $this->symbolPredicate->matchSymbol($symbol);
 }