/** * @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; }
/** * @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; }