/** * The main advance call required by the parser * * return true if a token is available, false if no more are available. * skips stuff that is not a valid token * stores lastcomment, lastcommenttoken * * * @return boolean - true = have tokens * @access public */ function advance() { $this->pos++; while ($this->pos < $this->N) { if ($this->debug) { echo token_name($this->tokens[$this->pos][0]) . '(' . PHPyyParser::tokenName(PHPyyParser::$transTable[$this->tokens[$this->pos[0]]]) . ')' . " : {$this->tokens[$this->pos][1]}\n"; } static $T_DOC_COMMENT = false; if (!$T_DOC_COMMENT) { $T_DOC_COMMENT = defined('T_DOC_COMMENT') ? constant('T_DOC_COMMENT') : 10000; } switch ($this->tokens[$this->pos][0]) { // simple ignore tags. case T_CLOSE_TAG: case T_OPEN_TAG_WITH_ECHO: $this->pos++; continue; // comments - store for phpdoc // comments - store for phpdoc case $T_DOC_COMMENT: case T_COMMENT: $this->lastComment = ''; $this->lastCommentToken = -1; $this->lastCommentLine = -1; if (substr($this->tokens[$this->pos][1], 0, 2) == '/*') { $this->_handleDocumentation(); } $this->line += substr_count($this->tokens[$this->pos][1], "\n"); $this->pos++; continue; $this->_handleDocumentation(); // ... continues into m/l skipeed tags.. // large // ... continues into m/l skipeed tags.. // large case T_OPEN_TAG: case T_INLINE_HTML: case T_ENCAPSED_AND_WHITESPACE: case T_WHITESPACE: if ($this->tokens[$this->pos][0] == T_WHITESPACE) { $this->_whitespace = $this->tokens[$this->pos][1]; } $this->line += substr_count($this->tokens[$this->pos][1], "\n"); $this->pos++; continue; //--- begin returnable values-- // end statement - clear any comment details. //--- begin returnable values-- // end statement - clear any comment details. case 59: // ord(';'): $this->lastComment = ''; $this->lastCommentToken = -1; // everything else! // everything else! default: $this->line += substr_count($this->tokens[$this->pos][1], "\n"); $this->token = $this->tokens[$this->pos][0]; $this->value = $this->tokens[$this->pos][1]; $this->token = PHPyyParser::$transTable[$this->token]; $this->valueWithWhitespace = $this->_whitespace . $this->value; $this->_whitespace = ''; return true; } } //echo "END OF FILE?"; return false; }
static function PrintTrace() { self::$yyTraceFILE = fopen('php://output', 'w'); self::$yyTracePrompt = ''; }
<?php require_once '/development/PHP_ParserGenerator/PHP_Parser.php'; require_once '/development/PHP_ParserGenerator/Tokenizer.php'; $a = new PHP_Parser_Tokenizer('<?php function test() { throw new Exception("boo"); } ?>'); $b = new PHPyyParser(); $b->printTrace(); while ($a->advance()) { $b->doParse($a->token, $a->getValue(), $a); } $b->doParse(0, 0);