Пример #1
0
 public function testVisitExpressionTreeOfOneLeaf()
 {
     $expression = ExpressionSymbol::createAdapterForTerminal('a');
     $eliminator = new OptionalsEliminator(new IncrementalNamingStrategy());
     $eliminator->visitExpression($expression);
     $actual = $eliminator->getRoot();
     $this->assertEquals($expression, $actual);
 }
Пример #2
0
 /**
  * @param Expression $e
  * @param \Helstern\Nomsky\Grammar\Transformations\EliminateOptionals\OptionalsEliminator $visitor
  *
  * @return Expression|null
  */
 public function walkAndVisitExpression(Expression $e, OptionalsEliminator $visitor)
 {
     $hierarchicVisitDispatcher = new CompleteVisitDispatcher($visitor);
     $walker = new DepthFirstStackBasedWalker();
     $walker->walk($e, $hierarchicVisitDispatcher);
     $walkResult = $visitor->getRoot();
     return $walkResult;
 }
Пример #3
0
 /**
 * @param Expression $e
 * @param NonTerminalNamingStrategy $namingStrategy
 *
 *@return Expression|null
 */
 public function getDepthFirstWalkResult(Expression $e, NonTerminalNamingStrategy $namingStrategy)
 {
     $visitor = new OptionalsEliminator($namingStrategy);
     $hierarchicVisitDispatcher = new CompleteVisitDispatcher($visitor);
     $walker = new DepthFirstStackBasedWalker();
     $walker->walk($e, $hierarchicVisitDispatcher);
     $walkResult = $visitor->getRoot();
     return $walkResult;
 }
Пример #4
0
 /**
  * @param Production $initialProduction
  * @return array|Production[]
  */
 public function transform(Production $initialProduction)
 {
     $expression = $initialProduction->getExpression();
     $visitor = new OptionalsEliminator($this->nonTerminalNamingStrategy);
     $hierarchicVisitDispatcher = new CompleteVisitDispatcher($visitor);
     $walker = new DepthFirstStackBasedWalker();
     $walker->walk($expression, $hierarchicVisitDispatcher);
     $visitRoot = $visitor->getRoot();
     $cleanedProduction = new StandardProduction($initialProduction->getNonTerminal(), $visitRoot);
     $cleanedProductionsList = array($cleanedProduction);
     $cleanedProductionsList = array_merge($cleanedProductionsList, $visitor->getEpsilonAlternatives());
     return $cleanedProductionsList;
 }