Пример #1
0
 /**
  * @return PHP_ParserGenerator_State
  */
 private function getstate()
 {
     /* Extract the sorted basis of the new state.  The basis was constructed
      ** by prior calls to "Configlist_addbasis()". */
     PHP_ParserGenerator_Config::Configlist_sortbasis();
     $bp = PHP_ParserGenerator_Config::Configlist_basis();
     /* Get a state with the same basis */
     $stp = PHP_ParserGenerator_State::State_find($bp);
     if ($stp) {
         /* A state with the same basis already exists!  Copy all the follow-set
          ** propagation links from the state under construction into the
          ** preexisting state, then return a pointer to the preexisting state */
         for ($x = $bp, $y = $stp->bp; $x && $y; $x = $x->bp, $y = $y->bp) {
             PHP_ParserGenerator_PropagationLink::Plink_copy($y->bplp, $x->bplp);
             PHP_ParserGenerator_PropagationLink::Plink_delete($x->fplp);
             $x->fplp = $x->bplp = 0;
         }
         $cfp = PHP_ParserGenerator_Config::Configlist_return();
         PHP_ParserGenerator_Config::Configlist_eat($cfp);
     } else {
         /* This really is a new state.  Construct all the details */
         PHP_ParserGenerator_Config::Configlist_closure($this);
         /* Compute the configuration closure */
         PHP_ParserGenerator_Config::Configlist_sort();
         /* Sort the configuration closure */
         $cfp = PHP_ParserGenerator_Config::Configlist_return();
         /* Get a pointer to the config list */
         $stp = new PHP_ParserGenerator_State();
         /* A new state structure */
         $stp->bp = $bp;
         /* Remember the configuration basis */
         $stp->cfp = $cfp;
         /* Remember the configuration closure */
         $stp->statenum = $this->nstate++;
         /* Every state gets a sequence number */
         $stp->ap = 0;
         /* No actions, yet. */
         PHP_ParserGenerator_State::State_insert($stp, $stp->bp);
         /* Add to the state table */
         // this can't work, recursion is too deep, move it into FindStates()
         //$this->buildshifts($stp);       /* Recursively compute successor states */
         return array($stp);
     }
     return $stp;
 }