예제 #1
0
 /**
  * @param \Helstern\Nomsky\Grammar\Grammar $g
  *
  * @return array|NormalizedProduction[]
  * @throws \Exception
  */
 public function normalize(Grammar $g)
 {
     $productions = $g->getProductions();
     $normalizedList = [];
     foreach ($productions as $p) {
         $normalized = $this->normalizeProduction($p);
         $normalizedList[] = $normalized;
     }
     return $normalizedList;
 }
예제 #2
0
 /**
  * @param Grammar $g
  * @return array|Production[]
  */
 public function convert(Grammar $g)
 {
     $productions = $g->getProductions();
     $intermediaryProductionsList = array_reverse($productions);
     foreach ($this->transformers as $transformer) {
         $tmpList = array();
         do {
             $production = array_pop($intermediaryProductionsList);
             $processed = $transformer->transform($production);
             $processed = array_reverse($processed);
             $tmpList = array_merge($processed, $tmpList);
         } while (!is_null(key($intermediaryProductionsList)));
         $intermediaryProductionsList = array_splice($tmpList, 0);
     }
     $convertedProductions = array_reverse($intermediaryProductionsList);
     return $convertedProductions;
 }
예제 #3
0
 /**
  * Creates an empty parse set
  *
  * @param Grammar $g
  *
  * @return ParseSets
  */
 public function createEmptyParseSets(Grammar $g)
 {
     $nonTerminals = $g->getNonTerminals();
     $sets = new ParseSets($nonTerminals);
     return $sets;
 }