/** * Get next token * @return PaccToken */ public function next() { do { $token = $this->stream->next(); } while (!$token instanceof PaccEndToken && isset($this->out[get_class($token)])); return $token; }
/** * @return array */ private function terms() { $terms = array(); while ($this->stream->current() instanceof PaccIdToken || $this->stream->current() instanceof PaccStringToken) { $t = $this->stream->current(); $this->stream->next(); if ($t instanceof PaccIdToken) { if (ord($t->value[0]) >= 65 && ord($t->value[0]) <= 90) { // terminal $term = new PaccTerminal($t->value, $t->value, NULL); if (($found = $this->terminals->find($term)) !== NULL) { $term = $found; } else { $this->terminals->add($term); } } else { // nonterminal $term = new PaccNonterminal($t->value); if (($found = $this->nonterminals->find($term)) !== NULL) { $term = $found; } else { $this->nonterminals->add($term); } } } else { assert($t instanceof PaccStringToken); $term = new PaccTerminal($t->value, NULL, $t->value); if (($found = $this->terminals->find($term)) !== NULL) { $term = $found; } else { $this->terminals->add($term); } } $terms[] = $term; } return $terms; }