/** * @override */ function get_rules($nt) { if (!isset($this->ntindex)) { $this->rebuild_index(); } return parent::get_rules($nt); }
/** * 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; } }