示例#1
0
文件: NFA.php 项目: carlosv2/fa
 /**
  * @return DFA
  */
 public function toDFA()
 {
     $closure = Closure::forStates($this->states);
     $map = [['closure' => $closure, 'state' => new DFAState($closure->isFinal())]];
     for ($i = 0; $i < count($map); $i++) {
         foreach ($map[$i]['closure']->getReachableSymbols() as $symbol) {
             $closure = $map[$i]['closure']->advance($symbol);
             $state = null;
             foreach ($map as $vector) {
                 if ($closure->isSameAs($vector['closure'])) {
                     $state = $vector['state'];
                 }
             }
             if (is_null($state)) {
                 $state = new DFAState($closure->isFinal());
                 $map[] = ['closure' => $closure, 'state' => $state];
             }
             $map[$i]['state']->on($symbol)->visit($state);
         }
     }
     return new DFA($map[0]['state']);
 }
示例#2
0
 function it_returns_false_if_two_closures_have_different_states(State $state1)
 {
     $closure = Closure::forStates([$state1->getWrappedObject()]);
     $this->shouldNotBeSameAs($closure);
 }