/** * Lookup which terminal symbols are permitted in a given state */ function permitted($state, Grammar $Grammar) { if (!isset($this->table[$state])) { return array(); } $all = array_keys($this->table[$state]); //return $all; $a = array(); foreach ($all as $t) { if ($Grammar->is_terminal($t)) { $a[] = $t; } } return $a; }
/** * Collect siblings states including self. * It is assumed that we only have one item at this point * @param array reference to populate * @return void */ function collect_states_passthru(&$states, Grammar $Grammar, array $excluded, $threadId) { if (isset($states[$this->id])) { // recursion return; } // check exclusions - These should only be passed when calling from a station, // so we know there is only one item and it is at the beginning of the rule. if ($excluded) { $s = $this->Item->current_symbol(); if (in_array($s, $excluded, true)) { //echo "Excluding state #$this->id because it begins with $s\n"; return; } if ($Grammar->is_terminal($s)) { //echo "Clearing exclude list in state #$this->id for descent beyond $s\n"; $excluded = array(); } //else { // echo "Passing down ",count($excluded)," exclusions through state #$this->id \n"; //} } $states[$this->id] = $this; foreach ($this->etransitions as $Station) { $Station->collect_states_recursive($states, $Grammar, $excluded, $threadId); } }