function parse_factor() { switch ($this->peek()) { case 'leftparen': $this->next(); $a = $this->parse_alternates(); $this->parse_terminal('rightparen'); return $a; case 'token': $t = $this->parse_terminal('token'); $n = new enfa(); $n->recognize($t); return $n; case 'epsilon': $t = $this->parse_terminal('epsilon'); $n = new enfa(); $n->add_epsilon($n->initial, $n->final); return $n; } die('CFG/PG got stuck parsing factors.'); }
function nfa_concat($nfa_list) { $out = new enfa(); $last_state = $out->initial; foreach ($nfa_list as $nfa) { $out->copy_in($nfa); $out->add_epsilon($last_state, $nfa->initial); $last_state = $nfa->final; } $out->add_epsilon($last_state, $out->final); return $out; }