Source for file Action.php
Documentation is available at Action.php
* PHP_ParserGenerator, a php 5 parser generator.
* This is a direct port of the Lemon parser generator, found at
* {@link http://www.hwaci.com/sw/lemon/}
* Copyright (c) 2006, Gregory Beaver <cellog@php.net>
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
* * Neither the name of the PHP_ParserGenerator nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @package PHP_ParserGenerator
* @author Gregory Beaver <cellog@php.net>
* @copyright 2006 Gregory Beaver
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @since File available since Release 0.1.0
* Every shift or reduce operation is stored as one of the following objects.
* @package PHP_ParserGenerator
* @author Gregory Beaver <cellog@php.net>
* @copyright 2006 Gregory Beaver
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version @package_version@
* @since Class available since Release 0.1.0
* Was a reduce, but part of a conflict
* Was a shift. Precedence resolved conflict
* Was a reduce. Precedence resolved conflict
* @see PHP_ParserGenerator::CompressTables()
* The look-ahead symbol that triggers this action
* @var PHP_ParserGenerator_Symbol
public $sp; /* The look-ahead symbol */
* This defines the kind of action, and must be one
* of the class constants.
* - {@link PHP_ParserGenerator_Action::SHIFT}
* - {@link PHP_ParserGenerator_Action::ACCEPT}
* - {@link PHP_ParserGenerator_Action::REDUCE}
* - {@link PHP_ParserGenerator_Action::ERROR}
* - {@link PHP_ParserGenerator_Action::CONFLICT}
* - {@link PHP_ParserGenerator_Action::SH_RESOLVED}
* - {@link PHP_ParserGenerator_Action:: RD_RESOLVED}
* - {@link PHP_ParserGenerator_Action::NOT_USED}
* The new state, if this is a shift,
* the parser rule index, if this is a reduce.
* @var PHP_ParserGenerator_State|PHP_ParserGenerator_Rule
* The next action for this state.
* @var PHP_ParserGenerator_Action
* This is used by {@link Action_sort()} to compare actions
static function actioncmp(PHP_ParserGenerator_Action $ap1,
PHP_ParserGenerator_Action $ap2)
$rc = $ap1->sp->index - $ap2->sp->index;
$rc = $ap1->type - $ap2->type;
if ($ap1->type != self::REDUCE &&
$ap1->type != self::RD_RESOLVED &&
$ap1->type != self::CONFLICT) {
throw new Exception('action has not been processed: ' .
if ($ap2->type != self::REDUCE &&
$ap2->type != self::RD_RESOLVED &&
$ap2->type != self::CONFLICT) {
throw new Exception('action has not been processed: ' .
$rc = $ap1->x->index - $ap2->x->index;
* create linked list of PHP_ParserGenerator_Actions
* @param PHP_ParserGenerator_Action|null
* @param int one of the class constants from PHP_ParserGenerator_Action
* @param PHP_ParserGenerator_Symbol
* @param PHP_ParserGenerator_Symbol|PHP_ParserGenerator_Rule
static function Action_add(&$app, $type, PHP_ParserGenerator_Symbol $sp, $arg)
* @see PHP_ParserGenerator_Data::FindActions()
static function Action_sort(PHP_ParserGenerator_Action $ap)
* Print an action to the given file descriptor. Return FALSE if
* nothing was actually printed.
* @see PHP_ParserGenerator_Data::ReportOutput()
fprintf($fp, "%${indent}s shift %d", $this->sp->name, $this->x->statenum);
fprintf($fp, "%${indent}s reduce %d", $this->sp->name, $this->x->index);
fprintf($fp, "%${indent}s reduce %-3d ** Parsing conflict **", $this->sp->name, $this->x->index);
|