phpDocumentor PHP_LexerGenerator
[ class tree: PHP_LexerGenerator ] [ index: PHP_LexerGenerator ] [ all elements ]

Source for file Parser.php

Documentation is available at Parser.php

  1. <?php
  2. /* Driver template for the PHP_PHP_LexerGenerator_Regex_rGenerator parser generator. (PHP port of LEMON)
  3. */
  4.  
  5. /**
  6.  * This can be used to store both the string representation of
  7.  * a token, and any useful meta-data associated with the token.
  8.  *
  9.  * meta-data should be stored as an array
  10.  */
  11. class PHP_LexerGenerator_Regex_yyToken implements ArrayAccess
  12. {
  13.     public $string = '';
  14.     public $metadata = array();
  15.  
  16.     function __construct($s$m array())
  17.     {
  18.         if ($s instanceof PHP_LexerGenerator_Regex_yyToken{
  19.             $this->string = $s->string;
  20.             $this->metadata = $s->metadata;
  21.         else {
  22.             $this->string = (string) $s;
  23.             if ($m instanceof PHP_LexerGenerator_Regex_yyToken{
  24.                 $this->metadata = $m->metadata;
  25.             elseif (is_array($m)) {
  26.                 $this->metadata = $m;
  27.             }
  28.         }
  29.     }
  30.  
  31.     function __toString()
  32.     {
  33.         return $this->_string;
  34.     }
  35.  
  36.     function offsetExists($offset)
  37.     {
  38.         return isset($this->metadata[$offset]);
  39.     }
  40.  
  41.     function offsetGet($offset)
  42.     {
  43.         return $this->metadata[$offset];
  44.     }
  45.  
  46.     function offsetSet($offset$value)
  47.     {
  48.         if ($offset === null{
  49.             if (isset($value[0])) {
  50.                 $x ($value instanceof PHP_LexerGenerator_Regex_yyToken?
  51.                     $value->metadata $value;
  52.                 $this->metadata = array_merge($this->metadata$x);
  53.                 return;
  54.             }
  55.             $offset count($this->metadata);
  56.         }
  57.         if ($value === null{
  58.             return;
  59.         }
  60.         if ($value instanceof PHP_LexerGenerator_Regex_yyToken{
  61.             if ($value->metadata{
  62.                 $this->metadata[$offset$value->metadata;
  63.             }
  64.         elseif ($value{
  65.             $this->metadata[$offset$value;
  66.         }
  67.     }
  68.  
  69.     function offsetUnset($offset)
  70.     {
  71.         unset($this->metadata[$offset]);
  72.     }
  73. }
  74.  
  75. /** The following structure represents a single element of the
  76.  * parser's stack.  Information stored includes:
  77.  *
  78.  *   +  The state number for the parser at this level of the stack.
  79.  *
  80.  *   +  The value of the token stored at this level of the stack.
  81.  *      (In other words, the "major" token.)
  82.  *
  83.  *   +  The semantic value stored at this level of the stack.  This is
  84.  *      the information used by the action routines in the grammar.
  85.  *      It is sometimes called the "minor" token.
  86.  */
  87. {
  88.     public $stateno;       /* The state-number */
  89.     public $major;         /* The major token value.  This is the code
  90.                      ** number for the token at this stack level */
  91.     public $minor/* The user-supplied minor token value.  This
  92.                      ** is the value of the token  */
  93. };
  94.  
  95. // code external to the class is included here
  96. #line 2 "Parser.y"
  97.  
  98. require_once 'PHP/LexerGenerator/Exception.php';
  99. #line 102 "Parser.php"
  100.  
  101. // declare_class is output here
  102. #line 5 "Parser.y"
  103. class PHP_LexerGenerator_Regex_Parser#line 107 "Parser.php"
  104. {
  105. /* First off, code is included which follows the "include_class" declaration
  106. ** in the input file. */
  107. #line 21 "Parser.y"
  108.  
  109.     
  110.     private $_lex;
  111.     private $_subpatterns;
  112.     private $_updatePattern;
  113.     private $_patternIndex;
  114.     public $result;
  115.     function __construct($lex)
  116.     {
  117.         $this->result = new PHP_LexerGenerator_ParseryyToken('');
  118.         $this->_lex $lex;
  119.         $this->_subpatterns 0;
  120.         $this->_patternIndex 1;
  121.     }
  122.  
  123.     function reset($patternIndex$updatePattern false)
  124.     {
  125.         $this->_updatePattern $updatePattern;
  126.         $this->_patternIndex $patternIndex;
  127.         $this->_subpatterns 0;
  128.         $this->result = new PHP_LexerGenerator_ParseryyToken('');
  129.     }
  130. #line 134 "Parser.php"
  131.  
  132. /* Next is all token values, as class constants
  133. */
  134. /* 
  135. ** These constants (all generated automatically by the parser generator)
  136. ** specify the various kinds of tokens (terminals) that the parser
  137. ** understands. 
  138. **
  139. ** Each symbol here is a terminal symbol in the grammar.
  140. */
  141.     const OPENPAREN                      =  1;
  142.     const OPENASSERTION                  =  2;
  143.     const BAR                            =  3;
  144.     const MULTIPLIER                     =  4;
  145.     const MATCHSTART                     =  5;
  146.     const MATCHEND                       =  6;
  147.     const OPENCHARCLASS                  =  7;
  148.     const CLOSECHARCLASS                 =  8;
  149.     const NEGATE                         =  9;
  150.     const TEXT                           10;
  151.     const CONTROLCHAR                    11;
  152.     const ESCAPEDBACKSLASH               12;
  153.     const HYPHEN                         13;
  154.     const BACKREFERENCE                  14;
  155.     const COULDBEBACKREF                 15;
  156.     const FULLSTOP                       16;
  157.     const INTERNALOPTIONS                17;
  158.     const CLOSEPAREN                     18;
  159.     const COLON                          19;
  160.     const POSITIVELOOKAHEAD              20;
  161.     const NEGATIVELOOKAHEAD              21;
  162.     const POSITIVELOOKBEHIND             22;
  163.     const NEGATIVELOOKBEHIND             23;
  164.     const PATTERNNAME                    24;
  165.     const ONCEONLY                       25;
  166.     const COMMENT                        26;
  167.     const RECUR                          27;
  168.     const YY_NO_ACTION 252;
  169.     const YY_ACCEPT_ACTION 251;
  170.     const YY_ERROR_ACTION 250;
  171.  
  172. /* Next are that tables used to determine what action to take based on the
  173. ** current state and lookahead token.  These tables are used to implement
  174. ** functions that take a state number and lookahead value and return an
  175. ** action integer.  
  176. **
  177. ** Suppose the action integer is N.  Then the action is determined as
  178. ** follows
  179. **
  180. **   0 <= N < self::YYNSTATE                              Shift N.  That is,
  181. **                                                        push the lookahead
  182. **                                                        token onto the stack
  183. **                                                        and goto state N.
  184. **
  185. **   self::YYNSTATE <= N < self::YYNSTATE+self::YYNRULE   Reduce by rule N-YYNSTATE.
  186. **
  187. **   N == self::YYNSTATE+self::YYNRULE                    A syntax error has occurred.
  188. **
  189. **   N == self::YYNSTATE+self::YYNRULE+1                  The parser accepts its
  190. **                                                        input. (and concludes parsing)
  191. **
  192. **   N == self::YYNSTATE+self::YYNRULE+2                  No such action.  Denotes unused
  193. **                                                        slots in the yy_action[] table.
  194. **
  195. ** The action table is constructed as a single large static array $yy_action.
  196. ** Given state S and lookahead X, the action is computed as
  197. **
  198. **      self::$yy_action[self::$yy_shift_ofst[S] + X ]
  199. **
  200. ** If the index value self::$yy_shift_ofst[S]+X is out of range or if the value
  201. ** self::$yy_lookahead[self::$yy_shift_ofst[S]+X] is not equal to X or if
  202. ** self::$yy_shift_ofst[S] is equal to self::YY_SHIFT_USE_DFLT, it means that
  203. ** the action is not in the table and that self::$yy_default[S] should be used instead.  
  204. **
  205. ** The formula above is for computing the action when the lookahead is
  206. ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
  207. ** a reduce action) then the static $yy_reduce_ofst array is used in place of
  208. ** the static $yy_shift_ofst array and self::YY_REDUCE_USE_DFLT is used in place of
  209. ** self::YY_SHIFT_USE_DFLT.
  210. **
  211. ** The following are the tables generated in this section:
  212. **
  213. **  self::$yy_action        A single table containing all actions.
  214. **  self::$yy_lookahead     A table containing the lookahead for each entry in
  215. **                          yy_action.  Used to detect hash collisions.
  216. **  self::$yy_shift_ofst    For each state, the offset into self::$yy_action for
  217. **                          shifting terminals.
  218. **  self::$yy_reduce_ofst   For each state, the offset into self::$yy_action for
  219. **                          shifting non-terminals after a reduce.
  220. **  self::$yy_default       Default action for each state.
  221. */
  222.     const YY_SZ_ACTTAB 367;
  223. static public $yy_action = array(
  224.  /*     0 */      251,   50,   16,   21,  128,  129,  141,  140,  139,  142,
  225.  /*    10 */      143,  145,  144,  138,   41,   16,   21,  128,  129,  141,
  226.  /*    20 */      140,  139,  142,  143,  145,  144,  138,   43,   16,   21,
  227.  /*    30 */      128,  129,  141,  140,  139,  142,  143,  145,  144,  138,
  228.  /*    40 */        98,   16,   21,  128,  129,  141,  140,  139,  142,  143,
  229.  /*    50 */      145,  144,  138,   32,   16,   21,  128,  129,  141,  140,
  230.  /*    60 */      139,  142,  143,  145,  144,  138,   39,   16,   21,  128,
  231.  /*    70 */      129,  141,  140,  139,  142,  143,  145,  144,  138,   31,
  232.  /*    80 */        16,   21,  128,  129,  141,  140,  139,  142,  143,  145,
  233.  /*    90 */      144,  138,   42,   16,   21,  128,  129,  141,  140,  139,
  234.  /*   100 */      142,  143,  145,  144,  138,   29,   16,   21,  128,  129,
  235.  /*   110 */      141,  140,  139,  142,  143,  145,  144,  138,   35,   16,
  236.  /*   120 */        21,  128,  129,  141,  140,  139,  142,  143,  145,  144,
  237.  /*   130 */      138,   40,   16,   21,  128,  129,  141,  140,  139,  142,
  238.  /*   140 */      143,  145,  144,  138,   37,   16,   21,  128,  129,  141,
  239.  /*   150 */      140,  139,  142,  143,  145,  144,  138,   38,   16,   21,
  240.  /*   160 */      128,  129,  141,  140,  139,  142,  143,  145,  144,  138,
  241.  /*   170 */        36,   16,   21,  128,  129,  141,  140,  139,  142,  143,
  242.  /*   180 */      145,  144,  138,   15,   21,  128,  129,  141,  140,  139,
  243.  /*   190 */      142,  143,  145,  144,  138,   54,   24,   23,   78,   75,
  244.  /*   200 */        76,   82,   83,   89,   88,   87,   84,   86,  112,  115,
  245.  /*   210 */      114,   34,   11,    1,    7,    8,    4,    2,    3,   13,
  246.  /*   220 */        52,   60,   10,   17,  102,  108,   14,   55,   18,   96,
  247.  /*   230 */        11,   47,   61,   48,  124,   46,   49,   51,   10,   17,
  248.  /*   240 */      106,   11,   11,   97,   18,   44,  103,   47,   61,   48,
  249.  /*   250 */        56,   46,   49,   51,   10,   17,   58,  132,  117,  111,
  250.  /*   260 */        18,  119,   12,   47,   61,   48,  122,   46,   49,   51,
  251.  /*   270 */        10,   17,    7,    8,    4,    2,   18,   28,   11,   47,
  252.  /*   280 */        61,   48,  135,   46,   49,   51,  116,  137,   65,  127,
  253.  /*   290 */        64,   63,   73,   79,  113,  120,   68,   70,   71,   11,
  254.  /*   300 */        67,   66,   69,   62,   26,   64,   63,   73,   99,  113,
  255.  /*   310 */      120,   19,   72,   74,   59,  126,   92,   80,   72,   74,
  256.  /*   320 */        59,   11,   92,   80,  123,  121,  118,  131,   93,  100,
  257.  /*   330 */      130,  136,  133,   11,   11,   11,   53,   11,   11,   11,
  258.  /*   340 */          6,    9,  107,  125,  110,  146,   33,   81,   57,   91,
  259.  /*   350 */      104,   85,  105,   94,   45,   27,   95,  101,   25,  109,
  260.  /*   360 */      134,   30,    5,   77,   20,   22,   90,
  261.     );
  262.     static public $yy_lookahead = array(
  263.  /*     0 */        29,   30,   31,   32,   33,   34,   35,   36,   37,   38,
  264.  /*    10 */        39,   40,   41,   42,   30,   31,   32,   33,   34,   35,
  265.  /*    20 */        36,   37,   38,   39,   40,   41,   42,   30,   31,   32,
  266.  /*    30 */        33,   34,   35,   36,   37,   38,   39,   40,   41,   42,
  267.  /*    40 */        30,   31,   32,   33,   34,   35,   36,   37,   38,   39,
  268.  /*    50 */        40,   41,   42,   30,   31,   32,   33,   34,   35,   36,
  269.  /*    60 */        37,   38,   39,   40,   41,   42,   30,   31,   32,   33,
  270.  /*    70 */        34,   35,   36,   37,   38,   39,   40,   41,   42,   30,
  271.  /*    80 */        31,   32,   33,   34,   35,   36,   37,   38,   39,   40,
  272.  /*    90 */        41,   42,   30,   31,   32,   33,   34,   35,   36,   37,
  273.  /*   100 */        38,   39,   40,   41,   42,   30,   31,   32,   33,   34,
  274.  /*   110 */        35,   36,   37,   38,   39,   40,   41,   42,   30,   31,
  275.  /*   120 */        32,   33,   34,   35,   36,   37,   38,   39,   40,   41,
  276.  /*   130 */        42,   30,   31,   32,   33,   34,   35,   36,   37,   38,
  277.  /*   140 */        39,   40,   41,   42,   30,   31,   32,   33,   34,   35,
  278.  /*   150 */        36,   37,   38,   39,   40,   41,   42,   30,   31,   32,
  279.  /*   160 */        33,   34,   35,   36,   37,   38,   39,   40,   41,   42,
  280.  /*   170 */        30,   31,   32,   33,   34,   35,   36,   37,   38,   39,
  281.  /*   180 */        40,   41,   42,   31,   32,   33,   34,   35,   36,   37,
  282.  /*   190 */        38,   39,   40,   41,   42,    1,    2,   32,   33,   34,
  283.  /*   200 */        35,   36,   37,   38,   39,   40,   41,   42,   10,   11,
  284.  /*   210 */        12,   17,    3,   19,   20,   21,   22,   23,   24,   25,
  285.  /*   220 */        26,   27,    1,    2,   10,   11,    5,   18,    7,   18,
  286.  /*   230 */          3,   10,   11,   12,    4,   14,   15,   16,    1,    2,
  287.  /*   240 */          4,    3,    3,    6,    7,   18,    4,   10,   11,   12,
  288.  /*   250 */        10,   14,   15,   16,    1,    2,   18,   18,    4,    6,
  289.  /*   260 */          7,   18,   19,   10,   11,   12,    4,   14,   15,   16,
  290.  /*   270 */          1,    2,   20,   21,   22,   23,    7,   13,    3,   10,
  291.  /*   280 */        11,   12,    4,   14,   15,   16,   10,   11,    8,    4,
  292.  /*   290 */        10,   11,   12,   18,   14,   15,   10,   11,   12,    3,
  293.  /*   300 */        14,   15,   16,    8,   13,   10,   11,   12,   18,   14,
  294.  /*   310 */        15,    9,   10,   11,   12,    4,   14,   15,   10,   11,
  295.  /*   320 */        12,    3,   14,   15,   10,   11,   12,   10,   11,   12,
  296.  /*   330 */        10,   11,   12,    3,    3,    3,   18,    3,    3,    3,
  297.  /*   340 */        36,   37,    4,    4,    4,    4,   13,    4,   18,   18,
  298.  /*   350 */        18,    4,   18,   18,   18,   13,    4,    4,   13,    4,
  299.  /*   360 */          4,   13,   18,    4,   43,   43,    4,
  300. );
  301.     const YY_SHIFT_USE_DFLT = -1;
  302.     const YY_SHIFT_MAX 74;
  303.     static public $yy_shift_ofst = array(
  304.  /*     0 */      221,  221,  221,  221,  221,  221,  221,  221,  221,  221,
  305.  /*    10 */      221,  221,  221,  221,  269,  237,  253,  194,  302,  308,
  306.  /*    20 */      280,  286,  295,  286,  252,  320,  317,  198,  314,  336,
  307.  /*    30 */      276,  239,  335,  214,  243,  332,  330,  318,  334,  275,
  308.  /*    40 */      209,  227,  331,  238,  362,  359,  230,  278,  262,  285,
  309.  /*    50 */      296,  311,  211,  254,  240,  356,  344,  353,  347,  333,
  310.  /*    60 */      290,  341,  340,  345