/** * Resolve non-deterministic automaton into a deterministic state tree * @return LRStateSet */ function resolve() { LRState::clear_index(); LRStation::clear_index(); // create Root Set // we SHOULD have a single etransition to an intial state return LRStateSet::init($this->etransitions[0], $this->Grammar); }
/** * Start recursive collection of e-transtions to states * @param Grammar * @param int number of symbols to look ahead, currently only 0 or 1 * @return void */ function collect_non_deterministic(Grammar $Grammar, $k) { // avoid recursion by testing if already collected if (isset($this->etransitions)) { return; } $this->etransitions = array(); // get all rules with our non-terminal as left had side foreach ($Grammar->get_rules($this->nt) as $r => $rule) { // create single Item for new state with pointer at start of rule $Item = LRItem::make($r, $rule, 0); if (isset($this->la) && $k === 1) { $Item->lookahead($this->la); } // create e-transition to state with single item $State = LRState::make($Item); $State->collect_non_deterministic($Grammar, $k); $this->etransitions[] = $State; } }
/** * Clear registered states * @return void */ static function clear_index() { self::$uindex = array(); self::$incid = 0; }