Source for file ActionTable.php
Documentation is available at ActionTable.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
* The state of the yy_action table under construction is an instance of
* the following structure
* @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
* Number of used slots in {@link $aAction}
* The $yy_action table under construction.
* Each entry is of format:
* 'lookahead' => -1, // Value of the lookahead token (symbol index)
* 'action' => -1 // Action to take on the given lookahead (action index)
* @see PHP_ParserGenerator_Data::compute_action()
* A single new transaction set.
* @see $aAction format of the internal array is described here
* The smallest (minimum) value of any lookahead token in {@link $aLookahead}
* The lowest non-terminal is always introduced earlier in the parser file,
* and is therefore a more significant token.
* The action associated with the smallest lookahead token.
* The largest (maximum) value of any lookahead token in {@link $aLookahead}
* The number of slots used in {@link $aLookahead}.
* This is the same as count($aLookahead), but there was no pressing reason
* to change this when porting from C.
* Add a new action to the current transaction set
'lookahead' => $lookahead,
* Add the transaction set built up with prior calls to acttab_action()
* into the current action table. Then reset the transaction set back
* to an empty set in preparation for a new round of acttab_action() calls.
* Return the offset into the action table of the new transaction.
* @return int Return the offset that should be added to the lookahead in
* order to get the index into $yy_action of the action. This will be used
* in generation of $yy_ofst tables (reduce and shift)
throw new Exception('nLookahead is not set up?');
/* Scan the existing action table looking for an offset where we can
** insert the current transaction set. Fall out of the loop when that
** offset is found. In the worst case, we fall out of the loop when
** i reaches $this->nAction, which means we append the new transaction set.
** i is the index in $this->aAction[] where $this->mnLookahead is inserted.
if ($this->aAction[$i]['lookahead'] < 0) {
if ($this->aAction[$k]['lookahead'] >= 0) {
for ($j = 0; $j < $this->nAction; $j++ ) {
if ($this->aAction[$j]['lookahead'] == $j +
break; /* Fits in empty slots */
if ($k < 0 || $k >= $this->nAction) {
for ($j = 0; $j < $this->nAction; $j++ ) {
if ($this->aAction[$j]['lookahead'] < 0) {
if ($this->aAction[$j]['lookahead'] == $j +
break; /* Same as a prior transaction set */
/* Insert transaction set at index i. */
/* Return the offset that is added to the lookahead in order to get the
** index into yy_action of the action */
|