[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * PHP_ParserGenerator, a php 5 parser generator. 4 * 5 * This is a direct port of the Lemon parser generator, found at 6 * {@link http://www.hwaci.com/sw/lemon/} 7 * 8 * PHP version 5 9 * 10 * LICENSE: This source file is subject to version 3.01 of the PHP license 11 * that is available through the world-wide-web at the following URI: 12 * http://www.php.net/license/3_01.txt. If you did not receive a copy of 13 * the PHP License and are unable to obtain it through the web, please 14 * send a note to [email protected] so we can mail you a copy immediately. 15 * 16 * @category php 17 * @package PHP_ParserGenerator 18 * @author Gregory Beaver <[email protected]> 19 * @copyright 2006 Gregory Beaver 20 * @license http://www.php.net/license/3_01.txt PHP License 3.01 21 * @version CVS: $Id$ 22 * @since File available since Release 0.1.0 23 */ 24 /** 25 * Every shift or reduce operation is stored as one of the following objects. 26 * 27 * @package PHP_ParserGenerator 28 * @author Gregory Beaver <[email protected]> 29 * @copyright 2006 Gregory Beaver 30 * @license http://www.php.net/license/3_01.txt PHP License 3.01 31 * @version 0.1.0 32 * @since Class available since Release 0.1.0 33 */ 34 class PHP_ParserGenerator_Action { 35 const SHIFT = 1, 36 ACCEPT = 2, 37 REDUCE = 3, 38 ERROR = 4, 39 /** 40 * Was a reduce, but part of a conflict 41 */ 42 CONFLICT = 5, 43 /** 44 * Was a shift. Precedence resolved conflict 45 */ 46 SH_RESOLVED = 6, 47 /** 48 * Was a reduce. Precedence resolved conflict 49 */ 50 RD_RESOLVED = 7, 51 /** 52 * Deleted by compression 53 * @see PHP_ParserGenerator::CompressTables() 54 */ 55 NOT_USED = 8; 56 /** 57 * The look-ahead symbol that triggers this action 58 * @var PHP_ParserGenerator_Symbol 59 */ 60 public $sp; /* The look-ahead symbol */ 61 /** 62 * This defines the kind of action, and must be one 63 * of the class constants. 64 * 65 * - {@link PHP_ParserGenerator_Action::SHIFT} 66 * - {@link PHP_ParserGenerator_Action::ACCEPT} 67 * - {@link PHP_ParserGenerator_Action::REDUCE} 68 * - {@link PHP_ParserGenerator_Action::ERROR} 69 * - {@link PHP_ParserGenerator_Action::CONFLICT} 70 * - {@link PHP_ParserGenerator_Action::SH_RESOLVED} 71 * - {@link PHP_ParserGenerator_Action:: RD_RESOLVED} 72 * - {@link PHP_ParserGenerator_Action::NOT_USED} 73 */ 74 public $type; 75 /** 76 * The new state, if this is a shift, 77 * the parser rule index, if this is a reduce. 78 * 79 * @var PHP_ParserGenerator_State|PHP_ParserGenerator_Rule 80 */ 81 public $x; 82 /** 83 * The next action for this state. 84 * @var PHP_ParserGenerator_Action 85 */ 86 public $next; 87 88 /** 89 * Compare two actions 90 * 91 * This is used by {@link Action_sort()} to compare actions 92 */ 93 static function actioncmp(PHP_ParserGenerator_Action $ap1, 94 PHP_ParserGenerator_Action $ap2) 95 { 96 $rc = $ap1->sp->index - $ap2->sp->index; 97 if ($rc === 0) { 98 $rc = $ap1->type - $ap2->type; 99 } 100 if ($rc === 0) { 101 if ($ap1->type != self::REDUCE && 102 $ap1->type != self::RD_RESOLVED && 103 $ap1->type != self::CONFLICT) { 104 throw new Exception('action has not been processed: ' . 105 $ap1->sp->name); 106 } 107 if ($ap2->type != self::REDUCE && 108 $ap2->type != self::RD_RESOLVED && 109 $ap2->type != self::CONFLICT) { 110 throw new Exception('action has not been processed: ' . 111 $ap2->sp->name); 112 } 113 $rc = $ap1->x->index - $ap2->x->index; 114 } 115 return $rc; 116 } 117 118 /** 119 * create linked list of PHP_ParserGenerator_Actions 120 * 121 * @param PHP_ParserGenerator_Action|null 122 * @param int one of the class constants from PHP_ParserGenerator_Action 123 * @param PHP_ParserGenerator_Symbol 124 * @param PHP_ParserGenerator_Symbol|PHP_ParserGenerator_Rule 125 */ 126 static function Action_add(&$app, $type, PHP_ParserGenerator_Symbol $sp, $arg) 127 { 128 $new = new PHP_ParserGenerator_Action; 129 $new->next = $app; 130 $app = $new; 131 $new->type = $type; 132 $new->sp = $sp; 133 $new->x = $arg; 134 } 135 136 /** 137 * Sort parser actions 138 * @see PHP_ParserGenerator_Data::FindActions() 139 */ 140 static function Action_sort(PHP_ParserGenerator_Action $ap) 141 { 142 $ap = PHP_ParserGenerator::msort($ap, 'next', array('PHP_ParserGenerator_Action', 'actioncmp')); 143 return $ap; 144 } 145 146 /** 147 * Print an action to the given file descriptor. Return FALSE if 148 * nothing was actually printed. 149 * @see PHP_ParserGenerator_Data::ReportOutput() 150 */ 151 function PrintAction($fp, $indent) 152 { 153 $result = 1; 154 switch ($this->type) 155 { 156 case self::SHIFT: 157 fprintf($fp, "%$indent}s shift %d", $this->sp->name, $this->x->statenum); 158 break; 159 case self::REDUCE: 160 fprintf($fp, "%$indent}s reduce %d", $this->sp->name, $this->x->index); 161 break; 162 case self::ACCEPT: 163 fprintf($fp, "%$indent}s accept", $this->sp->name); 164 break; 165 case self::ERROR: 166 fprintf($fp, "%$indent}s error", $this->sp->name); 167 break; 168 case self::CONFLICT: 169 fprintf($fp, "%$indent}s reduce %-3d ** Parsing conflict **", $this->sp->name, $this->x->index); 170 break; 171 case self::SH_RESOLVED: 172 case self::RD_RESOLVED: 173 case self::NOT_USED: 174 $result = 0; 175 break; 176 } 177 return $result; 178 } 179 } 180 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |