예제 #1
0
파일: DFA.php 프로젝트: carlosv2/fa
 /**
  * @return NFA
  */
 public function reverse()
 {
     $nfa = new NFA();
     $map = [spl_object_hash($this->state) => ['original' => $this->state, 'reversed' => new NFAState(true), 'starting' => $this->state->isFinal()]];
     for ($i = 0; $i < count($map); $i++) {
         $key = array_keys($map)[$i];
         if ($map[$key]['starting']) {
             $nfa->addStartingState($map[$key]['reversed']);
         }
         foreach ($map[$key]['original']->getTransitions() as $transition) {
             $state = $transition->getState();
             $hash = spl_object_hash($state);
             if (!array_key_exists($hash, $map)) {
                 $map[$hash] = ['original' => $state, 'reversed' => new NFAState(false), 'starting' => $state->isFinal()];
             }
             $map[$hash]['reversed']->on($transition->getSymbol())->visit($map[$key]['reversed']);
         }
     }
     return $nfa;
 }
예제 #2
0
파일: NFAContext.php 프로젝트: carlosv2/fa
 /**
  * @When I run the converted automaton
  */
 public function iRunTheConvertedAutomaton()
 {
     $nfa = new NFA();
     foreach ($this->startingStates as $state) {
         $nfa->addStartingState($state);
     }
     $this->result = $nfa->toDFA()->run($this->input);
 }