2011-04-18 19:02:30 +02:00
|
|
|
<?php
|
2011-05-31 16:33:11 +02:00
|
|
|
$meta #
|
|
|
|
#semval($) $this->yyval
|
|
|
|
#semval($,%t) $this->yyval
|
2012-05-05 17:34:27 +02:00
|
|
|
#semval(%n) $this->yyastk[$this->stackPos-(%l-%n)]
|
|
|
|
#semval(%n,%t) $this->yyastk[$this->stackPos-(%l-%n)]
|
2011-05-31 16:33:11 +02:00
|
|
|
#include;
|
2011-04-18 19:02:30 +02:00
|
|
|
|
2012-03-02 00:43:34 +01:00
|
|
|
/* This is an automatically GENERATED file, which should not be manually edited.
|
|
|
|
* Instead edit one of the following:
|
|
|
|
* * the grammar file grammar/zend_language_parser.phpy
|
2012-04-04 15:51:56 +02:00
|
|
|
* * the parser skeleton grammar/kymacc.php.parser
|
2012-03-02 00:43:34 +01:00
|
|
|
* * the preprocessing script grammar/rebuildParser.php
|
|
|
|
*
|
2012-04-04 15:51:56 +02:00
|
|
|
* The skeleton for this parser was written by Moriyoshi Koizumi and is based on
|
2012-03-02 00:43:34 +01:00
|
|
|
* the work by Masato Bito and is in the PUBLIC DOMAIN.
|
2011-04-18 19:02:30 +02:00
|
|
|
*/
|
2011-08-14 15:36:15 +02:00
|
|
|
#if -t
|
|
|
|
class #(-p)_Debug extends #(-p)
|
2011-05-31 16:33:11 +02:00
|
|
|
#endif
|
2011-08-14 15:36:15 +02:00
|
|
|
#ifnot -t
|
|
|
|
class #(-p)
|
2011-05-31 16:33:11 +02:00
|
|
|
#endif
|
2011-04-18 19:02:30 +02:00
|
|
|
{
|
2011-08-14 15:36:15 +02:00
|
|
|
#ifnot -t
|
2012-04-29 22:57:46 +02:00
|
|
|
const TOKEN_NONE = -1;
|
|
|
|
const TOKEN_INVALID = #(YYBADCH);
|
|
|
|
|
|
|
|
const TOKEN_MAP_SIZE = #(YYMAXLEX);
|
|
|
|
|
2011-05-31 16:33:11 +02:00
|
|
|
const YYLAST = #(YYLAST);
|
|
|
|
const YY2TBLSTATE = #(YY2TBLSTATE);
|
|
|
|
const YYGLAST = #(YYGLAST);
|
|
|
|
const YYNLSTATES = #(YYNLSTATES);
|
|
|
|
const YYUNEXPECTED = #(YYUNEXPECTED);
|
|
|
|
const YYDEFAULT = #(YYDEFAULT);
|
2011-04-18 19:02:30 +02:00
|
|
|
|
|
|
|
// {{{ Tokens
|
2011-05-31 16:33:11 +02:00
|
|
|
#tokenval
|
2011-04-18 19:02:30 +02:00
|
|
|
const %s = %n;
|
2011-05-31 16:33:11 +02:00
|
|
|
#endtokenval
|
2011-04-18 19:02:30 +02:00
|
|
|
// }}}
|
|
|
|
|
2012-04-29 22:57:46 +02:00
|
|
|
/* @var array Map of token ids to their respective names */
|
|
|
|
protected static $terminals = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar terminals
|
2011-04-18 19:02:30 +02:00
|
|
|
, "???"
|
|
|
|
);
|
|
|
|
|
2012-08-02 17:01:33 +02:00
|
|
|
/* @var array Map which translates lexer tokens to internal tokens */
|
2012-04-29 22:57:46 +02:00
|
|
|
protected static $translate = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yytranslate
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yyaction = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yyaction
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yycheck = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yycheck
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yybase = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yybase
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yydefault = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yydefault
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yygoto = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yygoto
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yygcheck = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yygcheck
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yygbase = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yygbase
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yygdefault = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yygdefault
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yylhs = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yylhs
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yylen = array(
|
2011-05-31 16:33:11 +02:00
|
|
|
#listvar yylen
|
2011-04-18 19:02:30 +02:00
|
|
|
);
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected $yyval;
|
|
|
|
protected $yyastk;
|
2012-05-05 17:34:27 +02:00
|
|
|
protected $stackPos;
|
2011-08-14 15:36:15 +02:00
|
|
|
protected $lexer;
|
2012-04-25 20:04:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a parser instance.
|
|
|
|
*
|
|
|
|
* @param PHPParser_Lexer $lexer A lexer
|
|
|
|
*/
|
|
|
|
public function __construct(PHPParser_Lexer $lexer) {
|
|
|
|
$this->lexer = $lexer;
|
|
|
|
}
|
2011-08-14 15:36:15 +02:00
|
|
|
#endif
|
2011-05-31 16:33:11 +02:00
|
|
|
#if -t
|
2011-08-14 15:36:15 +02:00
|
|
|
protected static $yyproduction = array(
|
|
|
|
#production-strings;
|
|
|
|
);
|
|
|
|
|
2011-04-18 19:02:30 +02:00
|
|
|
protected function yyprintln($msg) {
|
|
|
|
echo $msg, "\n";
|
|
|
|
}
|
|
|
|
|
2012-04-29 22:57:46 +02:00
|
|
|
protected function YYTRACE_NEWSTATE($state, $tokenId) {
|
2011-05-31 16:33:11 +02:00
|
|
|
$this->yyprintln(
|
|
|
|
'% State ' . $state
|
2012-04-29 22:57:46 +02:00
|
|
|
. ', Lookahead ' . ($tokenId == self::TOKEN_NONE ? '--none--' : self::$terminals[$tokenId])
|
2011-05-31 16:33:11 +02:00
|
|
|
);
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-29 22:57:46 +02:00
|
|
|
protected function YYTRACE_READ($tokenId) {
|
|
|
|
$this->yyprintln('% Reading ' . self::$terminals[$tokenId]);
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-29 22:57:46 +02:00
|
|
|
protected function YYTRACE_SHIFT($tokenId) {
|
|
|
|
$this->yyprintln('% Shift ' . self::$terminals[$tokenId]);
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected function YYTRACE_ACCEPT() {
|
2011-05-29 20:51:15 +02:00
|
|
|
$this->yyprintln('% Accepted.');
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected function YYTRACE_REDUCE($n) {
|
2011-05-29 20:51:15 +02:00
|
|
|
$this->yyprintln('% Reduce by (' . $n . ') ' . self::$yyproduction[$n]);
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected function YYTRACE_POP($state) {
|
2011-05-29 20:51:15 +02:00
|
|
|
$this->yyprintln('% Recovering, uncovers state ' . $state);
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-29 22:57:46 +02:00
|
|
|
protected function YYTRACE_DISCARD($tokenId) {
|
|
|
|
$this->yyprintln('% Discard ' . self::$terminals[$tokenId]);
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
2011-05-31 16:33:11 +02:00
|
|
|
#endif
|
|
|
|
|
2011-04-18 19:02:30 +02:00
|
|
|
/**
|
2011-05-31 16:33:11 +02:00
|
|
|
#ifnot -t
|
|
|
|
* Parses PHP code into a node tree.
|
|
|
|
#endif
|
|
|
|
#if -t
|
|
|
|
* Parses PHP code into a node tree and prints out debugging information.
|
|
|
|
#endif
|
|
|
|
*
|
2012-04-25 20:04:46 +02:00
|
|
|
* @param string $code The source code to parse
|
2011-05-31 16:33:11 +02:00
|
|
|
*
|
2012-12-21 13:26:58 +01:00
|
|
|
* @return PHPParser_Node[] Array of statements
|
2011-04-18 19:02:30 +02:00
|
|
|
*/
|
2012-04-25 20:04:46 +02:00
|
|
|
public function parse($code) {
|
|
|
|
$this->lexer->startLexing($code);
|
2011-06-12 17:19:12 +02:00
|
|
|
|
2012-05-05 17:34:27 +02:00
|
|
|
// We start off with no lookahead-token
|
2012-04-29 22:57:46 +02:00
|
|
|
$tokenId = self::TOKEN_NONE;
|
2011-04-18 19:02:30 +02:00
|
|
|
|
2012-05-05 17:34:27 +02:00
|
|
|
// The attributes for a node are taken from the first and last token of the node.
|
|
|
|
// From the first token only the startAttributes are taken and from the last only
|
|
|
|
// the endAttributes. Both are merged using the array union operator (+).
|
|
|
|
$startAttributes = array('startLine' => 1);
|
|
|
|
$endAttributes = array();
|
|
|
|
|
|
|
|
// In order to figure out the attributes for the starting token, we have to keep
|
|
|
|
// them in a stack
|
|
|
|
$attributeStack = array($startAttributes);
|
|
|
|
|
|
|
|
// Start off in the initial state and keep a stack of previous states
|
|
|
|
$state = 0;
|
|
|
|
$stateStack = array($state);
|
|
|
|
|
|
|
|
// AST stack (?)
|
|
|
|
$this->yyastk = array();
|
|
|
|
|
|
|
|
// Current position in the stack(s)
|
|
|
|
$this->stackPos = 0;
|
|
|
|
|
2011-04-18 19:02:30 +02:00
|
|
|
for (;;) {
|
2011-05-31 16:33:11 +02:00
|
|
|
#if -t
|
2012-04-29 22:57:46 +02:00
|
|
|
$this->YYTRACE_NEWSTATE($state, $tokenId);
|
|
|
|
|
2011-05-31 16:33:11 +02:00
|
|
|
#endif
|
2012-04-29 22:57:46 +02:00
|
|
|
if (self::$yybase[$state] == 0) {
|
|
|
|
$yyn = self::$yydefault[$state];
|
2011-04-18 19:02:30 +02:00
|
|
|
} else {
|
2012-04-29 22:57:46 +02:00
|
|
|
if ($tokenId === self::TOKEN_NONE) {
|
2012-11-20 16:04:24 +01:00
|
|
|
// Fetch the next token id from the lexer and fetch additional info by-ref.
|
|
|
|
// The end attributes are fetched into a temporary variable and only set once the token is really
|
|
|
|
// shifted (not during read). Otherwise you would sometimes get off-by-one errors, when a rule is
|
|
|
|
// reduced after a token was read but not yet shifted.
|
|
|
|
$origTokenId = $this->lexer->getNextToken($tokenValue, $startAttributes, $nextEndAttributes);
|
2012-04-29 22:57:46 +02:00
|
|
|
|
|
|
|
// map the lexer token id to the internally used token id's
|
|
|
|
$tokenId = $origTokenId >= 0 && $origTokenId < self::TOKEN_MAP_SIZE
|
|
|
|
? self::$translate[$origTokenId]
|
|
|
|
: self::TOKEN_INVALID;
|
|
|
|
|
|
|
|
if ($tokenId === self::TOKEN_INVALID) {
|
|
|
|
throw new RangeException(sprintf(
|
|
|
|
'The lexer returned an invalid token (id=%d, value=%s)',
|
|
|
|
$origTokenId, $tokenValue
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-05-05 17:34:27 +02:00
|
|
|
$attributeStack[$this->stackPos] = $startAttributes;
|
2011-05-31 16:33:11 +02:00
|
|
|
#if -t
|
2012-04-29 22:57:46 +02:00
|
|
|
|
|
|
|
$this->YYTRACE_READ($tokenId);
|
2011-05-31 16:33:11 +02:00
|
|
|
#endif
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
2012-04-29 22:57:46 +02:00
|
|
|
|
|
|
|
if ((($yyn = self::$yybase[$state] + $tokenId) >= 0
|
|
|
|
&& $yyn < self::YYLAST && self::$yycheck[$yyn] == $tokenId
|
|
|
|
|| ($state < self::YY2TBLSTATE
|
|
|
|
&& ($yyn = self::$yybase[$state + self::YYNLSTATES] + $tokenId) >= 0
|
2011-04-18 19:02:30 +02:00
|
|
|
&& $yyn < self::YYLAST
|
2012-04-29 22:57:46 +02:00
|
|
|
&& self::$yycheck[$yyn] == $tokenId))
|
2011-04-18 19:02:30 +02:00
|
|
|
&& ($yyn = self::$yyaction[$yyn]) != self::YYDEFAULT) {
|
|
|
|
/*
|
|
|
|
* >= YYNLSTATE: shift and reduce
|
|
|
|
* > 0: shift
|
|
|
|
* = 0: accept
|
|
|
|
* < 0: reduce
|
|
|
|
* = -YYUNEXPECTED: error
|
|
|
|
*/
|
|
|
|
if ($yyn > 0) {
|
|
|
|
/* shift */
|
2011-05-31 16:33:11 +02:00
|
|
|
#if -t
|
2012-04-29 22:57:46 +02:00
|
|
|
$this->YYTRACE_SHIFT($tokenId);
|
|
|
|
|
2011-05-31 16:33:11 +02:00
|
|
|
#endif
|
2012-05-05 17:34:27 +02:00
|
|
|
++$this->stackPos;
|
2011-04-18 19:02:30 +02:00
|
|
|
|
2012-05-05 17:34:27 +02:00
|
|
|
$stateStack[$this->stackPos] = $state = $yyn;
|
|
|
|
$this->yyastk[$this->stackPos] = $tokenValue;
|
|
|
|
$attributeStack[$this->stackPos] = $startAttributes;
|
2012-11-20 16:04:24 +01:00
|
|
|
$endAttributes = $nextEndAttributes;
|
2012-04-29 22:57:46 +02:00
|
|
|
$tokenId = self::TOKEN_NONE;
|
2011-04-18 19:02:30 +02:00
|
|
|
|
|
|
|
if ($yyn < self::YYNLSTATES)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* $yyn >= YYNLSTATES means shift-and-reduce */
|
|
|
|
$yyn -= self::YYNLSTATES;
|
|
|
|
} else {
|
|
|
|
$yyn = -$yyn;
|
|
|
|
}
|
|
|
|
} else {
|
2012-04-29 22:57:46 +02:00
|
|
|
$yyn = self::$yydefault[$state];
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* reduce/error */
|
|
|
|
if ($yyn == 0) {
|
|
|
|
/* accept */
|
2011-05-31 16:33:11 +02:00
|
|
|
#if -t
|
2011-04-18 19:02:30 +02:00
|
|
|
$this->YYTRACE_ACCEPT();
|
2011-05-31 16:33:11 +02:00
|
|
|
#endif
|
2011-04-20 13:40:29 +02:00
|
|
|
return $this->yyval;
|
2011-04-18 19:02:30 +02:00
|
|
|
} elseif ($yyn != self::YYUNEXPECTED) {
|
|
|
|
/* reduce */
|
2011-05-31 16:33:11 +02:00
|
|
|
#if -t
|
2011-04-18 19:02:30 +02:00
|
|
|
$this->YYTRACE_REDUCE($yyn);
|
2011-05-31 16:33:11 +02:00
|
|
|
#endif
|
2011-06-03 17:44:23 +02:00
|
|
|
try {
|
2011-07-03 16:35:45 +02:00
|
|
|
$this->{'yyn' . $yyn}(
|
2012-05-05 17:34:27 +02:00
|
|
|
$attributeStack[$this->stackPos - self::$yylen[$yyn]]
|
|
|
|
+ $endAttributes
|
2011-07-03 16:35:45 +02:00
|
|
|
);
|
2011-06-05 18:52:41 +02:00
|
|
|
} catch (PHPParser_Error $e) {
|
2011-11-27 12:53:48 +01:00
|
|
|
if (-1 === $e->getRawLine()) {
|
2012-05-05 17:34:27 +02:00
|
|
|
$e->setRawLine($startAttributes['startLine']);
|
2011-11-27 12:53:48 +01:00
|
|
|
}
|
2011-06-03 17:44:23 +02:00
|
|
|
|
|
|
|
throw $e;
|
|
|
|
}
|
2011-04-20 13:40:29 +02:00
|
|
|
|
|
|
|
/* Goto - shift nonterminal */
|
2012-05-05 17:34:27 +02:00
|
|
|
$this->stackPos -= self::$yylen[$yyn];
|
2011-04-20 13:40:29 +02:00
|
|
|
$yyn = self::$yylhs[$yyn];
|
2012-05-05 17:34:27 +02:00
|
|
|
if (($yyp = self::$yygbase[$yyn] + $stateStack[$this->stackPos]) >= 0
|
2011-04-20 13:40:29 +02:00
|
|
|
&& $yyp < self::YYGLAST
|
|
|
|
&& self::$yygcheck[$yyp] == $yyn) {
|
2012-04-29 22:57:46 +02:00
|
|
|
$state = self::$yygoto[$yyp];
|
2011-04-18 19:02:30 +02:00
|
|
|
} else {
|
2012-04-29 22:57:46 +02:00
|
|
|
$state = self::$yygdefault[$yyn];
|
2011-04-20 13:40:29 +02:00
|
|
|
}
|
2011-04-18 19:02:30 +02:00
|
|
|
|
2012-05-05 17:34:27 +02:00
|
|
|
++$this->stackPos;
|
2011-04-18 19:02:30 +02:00
|
|
|
|
2012-05-05 17:34:27 +02:00
|
|
|
$stateStack[$this->stackPos] = $state;
|
|
|
|
$this->yyastk[$this->stackPos] = $this->yyval;
|
|
|
|
$attributeStack[$this->stackPos] = $startAttributes;
|
2011-04-18 19:02:30 +02:00
|
|
|
} else {
|
|
|
|
/* error */
|
2013-01-15 17:26:20 +01:00
|
|
|
$expected = array();
|
|
|
|
|
|
|
|
$base = self::$yybase[$state];
|
|
|
|
for ($i = 0; $i < self::TOKEN_MAP_SIZE; ++$i) {
|
|
|
|
$n = $base + $i;
|
|
|
|
if ($n >= 0 && $n < self::YYLAST && self::$yycheck[$n] == $i
|
|
|
|
|| $state < self::YY2TBLSTATE
|
2013-07-27 18:48:49 +02:00
|
|
|
&& ($n = self::$yybase[$state + self::YYNLSTATES] + $i) >= 0
|
2013-01-15 17:26:20 +01:00
|
|
|
&& $n < self::YYLAST && self::$yycheck[$n] == $i
|
|
|
|
) {
|
|
|
|
if (self::$yyaction[$n] != self::YYUNEXPECTED) {
|
|
|
|
if (count($expected) == 4) {
|
|
|
|
/* Too many expected tokens */
|
|
|
|
$expected = array();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$expected[] = self::$terminals[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$expectedString = '';
|
|
|
|
if ($expected) {
|
|
|
|
$expectedString = ', expecting ' . implode(' or ', $expected);
|
|
|
|
}
|
|
|
|
|
2011-06-27 19:14:37 +02:00
|
|
|
throw new PHPParser_Error(
|
2013-01-15 17:26:20 +01:00
|
|
|
'Syntax error, unexpected ' . self::$terminals[$tokenId] . $expectedString,
|
2012-05-05 17:34:27 +02:00
|
|
|
$startAttributes['startLine']
|
2011-06-27 19:14:37 +02:00
|
|
|
);
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-29 22:57:46 +02:00
|
|
|
if ($state < self::YYNLSTATES)
|
2011-04-18 19:02:30 +02:00
|
|
|
break;
|
|
|
|
/* >= YYNLSTATES means shift-and-reduce */
|
2012-04-29 22:57:46 +02:00
|
|
|
$yyn = $state - self::YYNLSTATES;
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-14 15:36:15 +02:00
|
|
|
#ifnot -t
|
2011-05-31 16:33:11 +02:00
|
|
|
#reduce
|
2011-04-18 19:02:30 +02:00
|
|
|
|
2012-04-29 23:32:09 +02:00
|
|
|
protected function yyn%n($attributes) {
|
2011-04-18 19:02:30 +02:00
|
|
|
%b
|
|
|
|
}
|
2011-05-31 16:33:11 +02:00
|
|
|
#noact
|
2011-04-20 13:40:29 +02:00
|
|
|
|
2011-08-14 15:36:15 +02:00
|
|
|
protected function yyn%n() {
|
2012-05-05 17:34:27 +02:00
|
|
|
$this->yyval = $this->yyastk[$this->stackPos];
|
2011-04-20 13:40:29 +02:00
|
|
|
}
|
2011-05-31 16:33:11 +02:00
|
|
|
#endreduce
|
2011-08-14 15:36:15 +02:00
|
|
|
#endif
|
2011-04-18 19:02:30 +02:00
|
|
|
}
|
2011-05-31 16:33:11 +02:00
|
|
|
#tailcode;
|