CodeGen_PECL
[ class tree: CodeGen_PECL ] [ index: CodeGen_PECL ] [ all elements ]

Source for file ProtoParser.php

Documentation is available at ProtoParser.php

  1. <?php
  2. /* Driver template for the PHP_CodeGen_PECL_Tools_ProtoParser_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 CodeGen_PECL_Tools_ProtoParser_yyToken implements ArrayAccess
  12. {
  13.     public $string '';
  14.     public $metadata = array();
  15.  
  16.     function __construct($s$m = array())
  17.     {
  18.         if ($s instanceof CodeGen_PECL_Tools_ProtoParser_yyToken{
  19.             $this->string $s->string;
  20.             $this->metadata $s->metadata;
  21.         else {
  22.             $this->string = (string) $s;
  23.             if ($m instanceof CodeGen_PECL_Tools_ProtoParser_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 CodeGen_PECL_Tools_ProtoParser_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 CodeGen_PECL_Tools_ProtoParser_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. class CodeGen_PECL_Tools_ProtoParser_yyStackEntry
  88. {
  89.     public $stateno;       /* The state-number */
  90.     public $major;         /* The major token value.  This is the code
  91.                      ** number for the token at this stack level */
  92.     public $minor/* The user-supplied minor token value.  This
  93.                      ** is the value of the token  */
  94. };
  95.  
  96. // code external to the class is included here
  97.  
  98. // declare_class is output here
  99. #line 2 "ProtoParser.y"
  100. class CodeGen_PECL_Tools_ProtoParser#line 102 "ProtoParser.php"
  101. {
  102. /* First off, code is included which follows the "include_class" declaration
  103. ** in the input file. */
  104. #line 3 "ProtoParser.y"
  105.  
  106.   protected $extension;
  107.   protected $function;
  108.   protected $optParams;
  109.  
  110.   function __construct(CodeGen_PECL_Extension $extensionCodeGen_PECL_Element_Function $function)
  111.   {
  112.     $this->extension $extension;
  113.     $this->function  $function;
  114.     $this->optParams = array();
  115.   }
  116. #line 119 "ProtoParser.php"
  117.  
  118. /* Next is all token values, as class constants
  119. */
  120. /* 
  121. ** These constants (all generated automatically by the parser generator)
  122. ** specify the various kinds of tokens (terminals) that the parser
  123. ** understands. 
  124. **
  125. ** Each symbol here is a terminal symbol in the grammar.
  126. */
  127.     const SEMICOLON                      =  1;
  128.     const NAME                           =  2;
  129.     const PAR_OPEN                       =  3;
  130.     const PAR_CLOSE                      =  4;
  131.     const VOID                           =  5;
  132.     const AMPERSAND                      =  6;
  133.     const BOOL                           =  7;
  134.     const INT                            =  8;
  135.     const FLOAT                          =  9;
  136.     const STRING                         = 10;
  137.     const ARRAY_                         = 11;
  138.     const CLASS_                         = 12;
  139.     const RESOURCE                       = 13;
  140.     const MIXED                          = 14;
  141.     const CALLBACK                       = 15;
  142.     const STREAM                         = 16;
  143.     const SQUARE_OPEN                    = 17;
  144.     const SQUARE_CLOSE                   = 18;
  145.     const ELLIPSE                        = 19;
  146.     const COMMA                          = 20;
  147.     const EQ                             = 21;
  148.     const TRUE_                          = 22;
  149.     const FALSE_                         = 23;
  150.     const NULL_                          = 24;
  151.     const NUMVAL                         = 25;
  152.     const STRVAL                         = 26;
  153.     const YY_NO_ACTION = 102;
  154.     const YY_ACCEPT_ACTION = 101;
  155.     const YY_ERROR_ACTION = 100;
  156.  
  157. /* Next are that tables used to determine what action to take based on the
  158. ** current state and lookahead token.  These tables are used to implement
  159. ** functions that take a state number and lookahead value and return an
  160. ** action integer.  
  161. **
  162. ** Suppose the action integer is N.  Then the action is determined as
  163. ** follows
  164. **
  165. **   0 <= N < self::YYNSTATE                              Shift N.  That is,
  166. **                                                        push the lookahead
  167. **                                                        token onto the stack
  168. **                                                        and goto state N.
  169. **
  170. **   self::YYNSTATE <= N < self::YYNSTATE+self::YYNRULE   Reduce by rule N-YYNSTATE.
  171. **
  172. **   N == self::YYNSTATE+self::YYNRULE                    A syntax error has occurred.
  173. **
  174. **   N == self::YYNSTATE+self::YYNRULE+1                  The parser accepts its
  175. **                                                        input. (and concludes parsing)
  176. **
  177. **   N == self::YYNSTATE+self::YYNRULE+2                  No such action.  Denotes unused
  178. **                                                        slots in the yy_action[] table.
  179. **
  180. ** The action table is constructed as a single large static array $yy_action.
  181. ** Given state S and lookahead X, the action is computed as
  182. **
  183. **      self::$yy_action[self::$yy_shift_ofst[S] + X ]
  184. **
  185. ** If the index value self::$yy_shift_ofst[S]+X is out of range or if the value
  186. ** self::$yy_lookahead[self::$yy_shift_ofst[S]+X] is not equal to X or if
  187. ** self::$yy_shift_ofst[S] is equal to self::YY_SHIFT_USE_DFLT, it means that
  188. ** the action is not in the table and that self::$yy_default[S] should be used instead.  
  189. **
  190. ** The formula above is for computing the action when the lookahead is
  191. ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
  192. ** a reduce action) then the static $yy_reduce_ofst array is used in place of
  193. ** the static $yy_shift_ofst array and self::YY_REDUCE_USE_DFLT is used in place of
  194. ** self::YY_SHIFT_USE_DFLT.
  195. **
  196. ** The following are the tables generated in this section:
  197. **
  198. **  self::$yy_action        A single table containing all actions.
  199. **  self::$yy_lookahead     A table containing the lookahead for each entry in
  200. **                          yy_action.  Used to detect hash collisions.
  201. **  self::$yy_shift_ofst    For each state, the offset into self::$yy_action for
  202. **                          shifting terminals.
  203. **  self::$yy_reduce_ofst   For each state, the offset into self::$yy_action for
  204. **                          shifting non-terminals after a reduce.
  205. **  self::$yy_default       Default action for each state.
  206. */
  207.     const YY_SZ_ACTTAB = 100;
  208. static public $yy_action = array(
  209.  /*     0 */    36,   17,   29,   41,   53,   50,   44,   23,   22,   54,
  210.  /*    10 */    47,   48,    4,   34,   37,   29,   41,   53,   50,   44,
  211.  /*    20 */    23,   22,   54,   47,   48,   29,   41,   53,   50,   44,
  212.  /*    30 */    23,   22,   54,   47,   48,   25,    1,   42,   29,   41,
  213.  /*    40 */    53,   50,   44,   23,   22,   54,   47,   48,   40,    3,
  214.  /*    50 */    21,   12,   10,    8,   33,   16,   32,   18,  101,   11,
  215.  /*    60 */    24,   59,   35,   13,   12,    9,   27,   43,   57,   58,
  216.  /*    70 */    56,   55,   52,   12,   13,   27,    6,   12,   13,   45,
  217.  /*    80 */     7,   16,   16,   26,    2,   39,   49,   20,   30,   46,
  218.  /*    90 */    31,    5,   19,   51,   14,   38,   80,   15,   27,   28,
  219.     );
  220.     static public $yy_lookahead = array(
  221.  /*     0 */     5,    3,    7,    8,    9,   10,   11,   12,   13,   14,
  222.  /*    10 */    15,   16,   17,    5,   19,    7,    8,    9,   10,   11,
  223.  /*    20 */    12,   13,   14,   15,   16,    7,    8,    9,   10,   11,
  224.  /*    30 */    12,   13,   14,   15,   16,   18,    3,   19,    7,    8,
  225.  /*    40 */     9,   10,   11,   12,   13,   14,   15,   16,    2,   20,
  226.  /*    50 */    31,   32,   33,   34,   35,   17,   18,   11,   28,   29,
  227.  /*    60 */    30,    4,   32,   33,   32,   33,    6,   35,   22,   23,
  228.  /*    70 */    24,   25,   26,   32,   33,    6,   35,   32,   33,   19,
  229.  /*    80 */    35,   17,   17,   18,   20,   18,    2,    2,   19,    2,
  230.  /*    90 */     4,   21,    2,   37,   36,    1,   38,   36,    6,   36,
  231. );
  232.     const YY_SHIFT_USE_DFLT = -6;
  233.     const YY_SHIFT_MAX = 24;
  234.     static public $yy_shift_ofst = array(
  235.  /*     0 */     8,   -5,   18,   31,   31,   46,   38,   65,   64,   60,
  236.  /*    10 */    69,   94,   90,   92,   67,   17,   29,   57,   -2,   70,
  237.  /*    20 */    33,   86,   84,   87,   85,
  238. );
  239.     const YY_REDUCE_USE_DFLT = -1;
  240.     const YY_REDUCE_MAX = 8;
  241.     static public $yy_reduce_ofst = array(
  242.  /*     0 */    30,   19,   32,   45,   41,   56,   58,   61,   63,
  243. );
  244.     static public $yyExpectedTokens = array(
  245.         /* 0 */ array(578910111213141516),
  246.         /* 1 */ array(5789101112131415161719),
  247.         /* 2 */ array(7891011121314151619),
  248.         /* 3 */ array(78910111213141516),
  249.         /* 4 */ array(78910111213141516),
  250.         /* 5 */ array(2112223242526),
  251.         /* 6 */ array(1718),
  252.         /* 7 */ array(1718),
  253.         /* 8 */ array(1720),
  254.         /* 9 */ array(619),
  255.         /* 10 */ array(619),
  256.         /* 11 */ array(1),
  257.         /* 12 */ array(2),
  258.         /* 13 */ array(6),
  259.         /* 14 */ array(18),
  260.         /* 15 */ array(18),
  261.         /* 16 */ array(20),
  262.         /* 17 */ array(4),
  263.         /* 18 */ array(3),
  264.         /* 19 */ array(21),
  265.         /* 20 */ array(3),
  266.         /* 21 */ array(4),
  267.         /* 22 */ array(2),
  268.         /* 23 */ array(2),
  269.         /* 24 */ array(2),
  270.         /* 25 */ array(),
  271.         /* 26 */ array(),
  272.         /* 27 */ array(),
  273.         /* 28 */ array(),
  274.         /* 29 */ array(),
  275.         /* 30 */ array(),
  276.         /* 31 */ array(),
  277.         /* 32 */ array(),
  278.         /* 33 */ array(),
  279.         /* 34 */ array(),
  280.         /* 35 */ array(),
  281.         /* 36 */ array(),
  282.         /* 37 */ array(),
  283.         /* 38 */ array(),
  284.         /* 39 */ array(),
  285.         /* 40 */ array(),
  286.         /* 41 */ array(),
  287.         /* 42 */ array(),
  288.         /* 43 */ array(),
  289.         /* 44 */ array(),
  290.         /* 45 */ array(),
  291.         /* 46 */ array(),
  292.         /* 47 */ array(),
  293.         /* 48 */ array(),
  294.         /* 49 */ array(),
  295.         /* 50 */ array(),
  296.         /* 51 */ array(),
  297.         /* 52 */ array(),
  298.         /* 53 */ array(),
  299.         /* 54 */ array(),
  300.         /* 55 */ array(),
  301.         /* 56 */ array(),
  302.         /* 57 */ array(),
  303.         /* 58 */ array(),
  304.         /* 59 */ array(),
  305. );
  306.     static public $yy_default = array(
  307.  /*     0 */   100,   83,  100,  100,  100,  100,  100,  100,   77,   65,
  308.  /*    10 */    65,   60,  100,   65,  100,  100,  100,  100,  100,   91,
  309.  /*    20 */   100,  100,  100,  100,  100,   90,   89,   66,   87,   67,
  310.  /*    30 */    81,   62,   78,   88,   63,   64,   82,   80,   61,   79,
  311.  /*    40 */    99,   68,   84,   86,   71,   85,   72,   75,   76,   73,
  312.  /*    50 */    70,   92,   97,   69,   74,   96,   95,   93,   94,   98,
  313. );
  314. /* The next thing included is series of defines which control
  315. ** various aspects of the generated parser.
  316. **    self::YYNOCODE      is a number which corresponds
  317. **                        to no legal terminal or nonterminal number.  This
  318. **                        number is used to fill in empty slots of the hash 
  319. **                        table.
  320. **    self::YYFALLBACK    If defined, this indicates that one or more tokens
  321. **                        have fall-back values which should be used if the
  322. **                        original value of the token will not parse.
  323. **    self::YYSTACKDEPTH  is the maximum depth of the parser's stack.
  324. **    self::YYNSTATE      the combined number of states.
  325. **    self::YYNRULE       the number of rules in the grammar
  326. **    self::YYERRORSYMBOL is the code number of the error symbol.  If not
  327. **                        defined, then do no error processing.
  328. */
  329.     const YYNOCODE = 39;
  330.     const YYSTACKDEPTH = 100;
  331.     const YYNSTATE = 60;
  332.     const YYNRULE = 40;
  333.     const YYERRORSYMBOL = 27;
  334.     const YYERRSYMDT = 'yy0';
  335.     const YYFALLBACK = 0;
  336.     /** The next table maps tokens into fallback tokens.  If a construct
  337.      * like the following:
  338.      * 
  339.      *      %fallback ID X Y Z.
  340.      *
  341.      * appears in the grammer, then ID becomes a fallback token for X, Y,
  342.      * and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
  343.      * but it does not parse, the type of the token is changed to ID and
  344.      * the parse is retried before an error is thrown.
  345.      */
  346.     static public $yyFallback = array(
  347.     );
  348.     /**
  349.      * Turn parser tracing on by giving a stream to which to write the trace
  350.      * and a prompt to preface each trace message.  Tracing is turned off
  351.      * by making either argument NULL
  352.      *
  353.      * Inputs:
  354.      * 
  355.      * - A stream resource to which trace output should be written.
  356.      *   If NULL, then tracing is turned off.
  357.      * - A prefix string written at the beginning of every
  358.      *   line of trace output.  If NULL, then tracing is
  359.      *   turned off.
  360.      *
  361.      * Outputs:
  362.      * 
  363.      * - None.
  364.      * @param resource 
  365.      * @param string 
  366.      */
  367.     static function Trace($TraceFILE$zTracePrompt)
  368.     {
  369.         if (!$TraceFILE{
  370.             $zTracePrompt = 0;
  371.         elseif (!$zTracePrompt{
  372.             $TraceFILE = 0;
  373.         }
  374.         self::$yyTraceFILE $TraceFILE;
  375.         self::$yyTracePrompt $zTracePrompt;
  376.     }
  377.  
  378.     /**
  379.      * Output debug information to output (php://output stream)
  380.      */
  381.     static function PrintTrace()
  382.     {
  383.         self::$yyTraceFILE = fopen('php://output''w');
  384.         self::$yyTracePrompt '';
  385.     }
  386.  
  387.     /**
  388.      * @var resource|0
  389.      */
  390.     static public $yyTraceFILE;
  391.     /**
  392.      * String to prepend to debug output
  393.      * @var string|0
  394.      */
  395.     static public $yyTracePrompt;
  396.     /**
  397.      * @var int 
  398.      */
  399.     public $yyidx;                    /* Index of top element in stack */
  400.     /**
  401.      * @var int 
  402.      */
  403.     public $yyerrcnt;                 /* Shifts left before out of the error */
  404.     /**
  405.      * @var array 
  406.      */
  407.     public $yystack = array();  /* The parser's stack */
  408.  
  409.     /**
  410.      * For tracing shifts, the names of all terminals and nonterminals
  411.      * are required.  The following table supplies these names
  412.      * @var array 
  413.      */
  414.     static public $yyTokenName = array
  415.   '$',             'SEMICOLON',     'NAME',          'PAR_OPEN',    
  416.   'PAR_CLOSE',     'VOID',          'AMPERSAND',     'BOOL',        
  417.   'INT',           'FLOAT',         'STRING',        'ARRAY_',      
  418.   'CLASS_',        'RESOURCE',      'MIXED',         'CALLBACK',    
  419.   'STREAM',        'SQUARE_OPEN',   'SQUARE_CLOSE',  'ELLIPSE',     
  420.   'COMMA',         'EQ',            'TRUE_',         'FALSE_',      
  421.   'NULL_',         'NUMVAL',        'STRVAL',        'error',       
  422.   'proto_line',    'proto',         'rettype',       'param_spec',  
  423.   'typespec',      'typename',      'param_list',    'param',       
  424.   'optional_params',  'default',     
  425.     );
  426.  
  427.     /**
  428.      * For tracing reduce actions, the names of all rules are required.
  429.      * @var array 
  430.      */
  431.     static public $yyRuleName = array(
  432.  /*   0 */ "proto_line ::= proto",
  433.  /*   1 */ "proto_line ::= proto SEMICOLON",
  434.  /*   2 */ "proto ::= rettype NAME PAR_OPEN param_spec PAR_CLOSE",
  435.  /*   3 */ "rettype ::= VOID",
  436.  /*   4 */ "rettype ::= typespec",
  437.  /*   5 */ "typespec ::= typename",
  438.  /*   6 */ "typespec ::= typename AMPERSAND",
  439.  /*   7 */ "typename ::= BOOL",
  440.  /*   8 */ "typename ::= INT",
  441.  /*   9 */ "typename ::= FLOAT",
  442.  /*  10 */ "typename ::= STRING",
  443.  /*  11 */ "typename ::= ARRAY_",
  444.  /*  12 */ "typename ::= CLASS_ NAME",
  445.  /*  13 */ "typename ::= RESOURCE NAME",
  446.  /*  14 */ "typename ::= MIXED",
  447.  /*  15 */ "typename ::= CALLBACK",
  448.  /*  16 */ "typename ::= STREAM",
  449.  /*  17 */ "param_spec ::= param_list",
  450.  /*  18 */ "param_spec ::= SQUARE_OPEN param SQUARE_CLOSE",
  451.  /*  19 */ "param_spec ::= SQUARE_OPEN param optional_params SQUARE_CLOSE",
  452.  /*  20 */ "param_spec ::= ELLIPSE",
  453.  /*  21 */ "param_spec ::= typename ELLIPSE",
  454.  /*  22 */ "param_spec ::= VOID",
  455.  /*  23 */ "param_spec ::=",
  456.  /*  24 */ "param_list ::= param_list COMMA ELLIPSE",
  457.  /*  25 */ "param_list ::= param_list COMMA typename ELLIPSE",
  458.  /*  26 */ "param_list ::= param_list COMMA param",
  459.  /*  27 */ "param_list ::= param_list optional_params",
  460.  /*  28 */ "param_list ::= param",
  461.  /*  29 */ "optional_params ::= SQUARE_OPEN COMMA param SQUARE_CLOSE",
  462.  /*  30 */ "optional_params ::= SQUARE_OPEN COMMA param optional_params SQUARE_CLOSE",
  463.  /*  31 */ "param ::= typespec NAME",
  464.  /*  32 */ "param ::= typespec NAME EQ default",
  465.  /*  33 */ "default ::= TRUE_",
  466.  /*  34 */ "default ::= FALSE_",
  467.  /*  35 */ "default ::= NULL_",
  468.  /*  36 */ "default ::= NUMVAL",
  469.  /*  37 */ "default ::= STRVAL",
  470.  /*  38 */ "default ::= ARRAY_ PAR_OPEN PAR_CLOSE",
  471.  /*  39 */ "default ::= NAME",
  472.     );
  473.  
  474.     /**
  475.      * This function returns the symbolic name associated with a token
  476.      * value.
  477.      * @param int 
  478.      * @return string 
  479.      */
  480.     function tokenName($tokenType)
  481.     {
  482.         if ($tokenType === 0{
  483.             return 'End of Input';
  484.         }
  485.         if ($tokenType > 0 && $tokenType < count(self::$yyTokenName)) {
  486.             return self::$yyTokenName[$tokenType];
  487.         else {
  488.             return "Unknown";
  489.         }
  490.     }
  491.  
  492.     /**
  493.      * The following function deletes the value associated with a
  494.      * symbol.  The symbol can be either a terminal or nonterminal.
  495.      * @param int the symbol code
  496.      * @param mixed the symbol's value
  497.      */
  498.     static function yy_destructor($yymajor$yypminor)
  499.     {
  500.         switch ($yymajor{
  501.         /* Here is inserted the actions which take place when a
  502.         ** terminal or non-terminal is destroyed.  This can happen
  503.         ** when the symbol is popped from the stack during a
  504.         ** reduce or during error processing or when a parser is 
  505.         ** being destroyed before it is finished parsing.
  506.         **
  507.         ** Note: during a reduce, the only symbols destroyed are those
  508.         ** which appear on the RHS of the rule, but which are not used
  509.         ** inside the C code.
  510.         */
  511.             default:  break;   /* If no destructor action specified: do nothing */
  512.         }
  513.     }
  514.  
  515.     /**
  516.      * Pop the parser's stack once.
  517.      *
  518.      * If there is a destructor routine associated with the token which
  519.      * is popped from the stack, then call it.
  520.      *
  521.      * Return the major token number for the symbol popped.
  522.      * @param CodeGen_PECL_Tools_ProtoParser_yyParser 
  523.      * @return int 
  524.      */
  525.     function yy_pop_parser_stack()
  526.     {
  527.         if (!count($this->yystack)) {
  528.             return;
  529.         }
  530.         $yytos array_pop($this->yystack);
  531.         if (self::$yyTraceFILE && $this->yyidx >= 0{
  532.             fwrite(self::$yyTraceFILE,
  533.                 self::$yyTracePrompt 'Popping ' . self::$yyTokenName[$yytos->major.
  534.                     "\n");
  535.         }
  536.         $yymajor $yytos->major;
  537.         self::yy_destructor($yymajor$yytos->minor);
  538.         $this->yyidx--;
  539.         return $yymajor;
  540.     }
  541.  
  542.     /**
  543.      * Deallocate and destroy a parser.  Destructors are all called for
  544.      * all stack elements before shutting the parser down.
  545.      */
  546.     function __destruct()
  547.     {
  548.         while ($this->yyidx >= 0{
  549.             $this->yy_pop_parser_stack();
  550.         }
  551.         if (is_resource(self::$yyTraceFILE)) {
  552.             fclose(self::$yyTraceFILE);
  553.         }
  554.     }
  555.  
  556.     /**
  557.      * Based on the current state and parser stack, get a list of all
  558.      * possible lookahead tokens
  559.      * @param int 
  560.      * @return array 
  561.      */
  562.     function yy_get_expected_tokens($token)
  563.     {
  564.         $state $this->yystack[$this->yyidx]->stateno;
  565.         $expected = self::$yyExpectedTokens[$state];
  566.         if (in_array($tokenself::$yyExpectedTokens[$state]true)) {
  567.             return $expected;
  568.         }
  569.         $stack $this->yystack;
  570.         $yyidx $this->yyidx;
  571.         do {
  572.             $yyact $this->yy_find_shift_action($token);
  573.             if ($yyact >= self::YYNSTATE && $yyact < self::YYNSTATE + self::YYNRULE{
  574.                 // reduce action
  575.                 $done = 0;
  576.                 do {
  577.                     if ($done++ == 100{
  578.                         $this->yyidx $yyidx;
  579.                         $this->yystack $stack;
  580.                         // too much recursion prevents proper detection
  581.                         // so give up
  582.                         return array_unique($expected);
  583.                     }
  584.                     $yyruleno $yyact - self::YYNSTATE;
  585.                     $this->yyidx -= self::$yyRuleInfo[$yyruleno]['rhs'];
  586.                     $nextstate $this->yy_find_reduce_action(
  587.                         $this->yystack[$this->yyidx]->stateno,
  588.                         self::$yyRuleInfo[$yyruleno]['lhs']);
  589.                     if (isset(self::$yyExpectedTokens[$nextstate])) {
  590.                         $expected += self::$yyExpectedTokens[$nextstate];
  591.                             if (in_array($token,
  592.                                   self::$yyExpectedTokens[$nextstate]true)) {
  593.                             $this->yyidx $yyidx;
  594.                             $this->yystack $stack;
  595.                             return array_unique($expected);
  596.                         }
  597.                     }
  598.                     if ($nextstate < self::YYNSTATE{
  599.                         // we need to shift a non-terminal
  600.                         $this->yyidx++;
  601.                         $x = new CodeGen_PECL_Tools_ProtoParser_yyStackEntry;
  602.                         $x->stateno = $nextstate;
  603.                         $x->major = self::$yyRuleInfo[$yyruleno]['lhs'];
  604.                         $this->yystack[$this->yyidx$x;
  605.                         continue 2;
  606.                     elseif ($nextstate == self::YYNSTATE + self::YYNRULE + 1{
  607.                         $this->yyidx $yyidx;
  608.                         $this->yystack $stack;
  609.                         // the last token was just ignored, we can't accept
  610.                         // by ignoring input, this is in essence ignoring a
  611.                         // syntax error!
  612.                         return array_unique($expected);
  613.                     elseif ($nextstate === self::YY_NO_ACTION{
  614.                         $this->yyidx $yyidx;
  615.                         $this->yystack $stack;
  616.                         // input accepted, but not shifted (I guess)
  617.                         return $expected;
  618.                     else {
  619.                         $yyact $nextstate;
  620.                     }
  621.                 while (true);
  622.             }
  623.             break;
  624.         while (true);
  625.         return array_unique($expected);
  626.     }
  627.  
  628.     /**
  629.      * Based on the parser state and current parser stack, determine whether
  630.      * the lookahead token is possible.
  631.      * 
  632.      * The parser will convert the token value to an error token if not.  This
  633.      * catches some unusual edge cases where the parser would fail.
  634.      * @param int 
  635.      * @return bool 
  636.      */
  637.     function yy_is_expected_token($token)
  638.     {
  639.         if ($token === 0{
  640.             return true; // 0 is not part of this
  641.         }
  642.         $state $this->yystack[$this->yyidx]->stateno;
  643.         if (in_array($tokenself::$yyExpectedTokens[$state]true)) {
  644.             return true;
  645.         }
  646.         $stack $this->yystack;
  647.         $yyidx $this->yyidx;
  648.         do {
  649.             $yyact $this->yy_find_shift_action($token);
  650.             if ($yyact >= self::YYNSTATE && $yyact < self::YYNSTATE + self::YYNRULE{
  651.                 // reduce action
  652.                 $done = 0;
  653.                 do {
  654.                     if ($done++ == 100{
  655.                         $this->yyidx $yyidx;
  656.                         $this->yystack $stack;
  657.                         // too much recursion prevents proper detection
  658.                         // so give up
  659.                         return true;
  660.                     }
  661.                     $yyruleno $yyact - self::YYNSTATE;
  662.                     $this->yyidx -= self::$yyRuleInfo[$yyruleno]['rhs'];
  663.                     $nextstate $this->yy_find_reduce_action(
  664.                         $this->yystack[$this->yyidx]->stateno,
  665.                         self::$yyRuleInfo[$yyruleno]['lhs']);
  666.                     if (isset(self::$yyExpectedTokens[$nextstate]&&
  667.                           in_array($tokenself::$yyExpectedTokens[$nextstate]true)) {
  668.                         $this->yyidx $yyidx;
  669.                         $this->yystack $stack;
  670.                         return true;
  671.                     }
  672.                     if ($nextstate < self::YYNSTATE{
  673.                         // we need to shift a non-terminal
  674.                         $this->yyidx++;
  675.                         $x = new CodeGen_PECL_Tools_ProtoParser_yyStackEntry;
  676.                         $x->stateno = $nextstate;
  677.                         $x->major = self::$yyRuleInfo[$yyruleno]['lhs'];
  678.                         $this->yystack[$this->yyidx$x;
  679.                         continue 2;
  680.                     elseif ($nextstate == self::YYNSTATE + self::YYNRULE + 1{
  681.                         $this->yyidx $yyidx;
  682.                         $this->yystack $stack;
  683.                         if (!$token{
  684.                             // end of input: this is valid
  685.                             return true;
  686.                         }
  687.                         // the last token was just ignored, we can't accept
  688.                         // by ignoring input, this is in essence ignoring a
  689.                         // syntax error!
  690.                         return false;
  691.                     elseif ($nextstate === self::YY_NO_ACTION{
  692.                         $this->yyidx $yyidx;
  693.                         $this->yystack $stack;
  694.                         // input accepted, but not shifted (I guess)
  695.                         return true;
  696.                     else {
  697.                         $yyact $nextstate;
  698.                     }
  699.                 while (true);
  700.             }
  701.             break;
  702.         while (true);
  703.         $this->yyidx $yyidx;
  704.         $this->yystack $stack;
  705.         return true;
  706.     }
  707.  
  708.     /**
  709.      * Find the appropriate action for a parser given the terminal
  710.      * look-ahead token iLookAhead.
  711.      *
  712.      * If the look-ahead token is YYNOCODE, then check to see if the action is
  713.      * independent of the look-ahead.  If it is, return the action, otherwise
  714.      * return YY_NO_ACTION.
  715.      * @param int The look-ahead token
  716.      */
  717.     function yy_find_shift_action($iLookAhead)
  718.     {
  719.         $stateno $this->yystack[$this->yyidx]->stateno;
  720.      
  721.         /* if ($this->yyidx < 0) return self::YY_NO_ACTION;  */
  722.         if (!isset(self::$yy_shift_ofst[$stateno])) {
  723.             // no shift actions
  724.             return self::$yy_default[$stateno];
  725.         }
  726.         $i = self::$yy_shift_ofst[$stateno];
  727.         if ($i === self::YY_SHIFT_USE_DFLT{
  728.             return self::$yy_default[$stateno];
  729.         }
  730.         if ($iLookAhead == self::YYNOCODE{
  731.             return self::YY_NO_ACTION;
  732.         }
  733.         $i += $iLookAhead;
  734.         if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
  735.               self::$yy_lookahead[$i!= $iLookAhead{
  736.             if (count(self::$yyFallback&& $iLookAhead < count(self::$yyFallback)
  737.                    && ($iFallback = self::$yyFallback[$iLookAhead]!= 0{
  738.                 if (self::$yyTraceFILE{
  739.                     fwrite(self::$yyTraceFILEself::$yyTracePrompt "FALLBACK " .
  740.                         self::$yyTokenName[$iLookAhead" => " .
  741.                         self::$yyTokenName[$iFallback"\n");
  742.                 }
  743.                 return $this->yy_find_shift_action($iFallback);
  744.             }
  745.             return self::$yy_default[$stateno];
  746.         else {
  747.             return self::$yy_action[$i];
  748.         }
  749.     }
  750.  
  751.     /**
  752.      * Find the appropriate action for a parser given the non-terminal
  753.      * look-ahead token $iLookAhead.
  754.      *
  755.      * If the look-ahead token is self::YYNOCODE, then check to see if the action is
  756.      * independent of the look-ahead.  If it is, return the action, otherwise
  757.      * return self::YY_NO_ACTION.
  758.      * @param int Current state number
  759.      * @param int The look-ahead token
  760.      */
  761.     function yy_find_reduce_action($stateno$iLookAhead)
  762.     {
  763.         /* $stateno = $this->yystack[$this->yyidx]->stateno; */
  764.  
  765.         if (!isset(self::$yy_reduce_ofst[$stateno])) {
  766.             return self::$yy_default[$stateno];
  767.         }
  768.         $i = self::$yy_reduce_ofst[$stateno];
  769.         if ($i == self::YY_REDUCE_USE_DFLT{
  770.             return self::$yy_default[$stateno];
  771.         }
  772.         if ($iLookAhead == self::YYNOCODE{
  773.             return self::YY_NO_ACTION;
  774.         }
  775.         $i += $iLookAhead;
  776.         if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
  777.               self::$yy_lookahead[$i!= $iLookAhead{
  778.             return self::$yy_default[$stateno];
  779.         else {
  780.             return self::$yy_action[$i];
  781.         }
  782.     }
  783.  
  784.     /**
  785.      * Perform a shift action.
  786.      * @param int The new state to shift in
  787.      * @param int The major token to shift in
  788.      * @param mixed the minor token to shift in
  789.      */
  790.     function yy_shift($yyNewState$yyMajor$yypMinor)
  791.     {
  792.         $this->yyidx++;
  793.         if ($this->yyidx >= self::YYSTACKDEPTH{
  794.             $this->yyidx--;
  795.             if (self::$yyTraceFILE{
  796.                 fprintf(self::$yyTraceFILE"%sStack Overflow!\n"self::$yyTracePrompt);
  797.             }
  798.             while ($this->yyidx >= 0{
  799.                 $this->yy_pop_parser_stack();
  800.             }
  801.             /* Here code is inserted which will execute if the parser
  802.             ** stack ever overflows */
  803.             return;
  804.         }
  805.         $yytos = new CodeGen_PECL_Tools_ProtoParser_yyStackEntry;
  806.         $yytos->stateno = $yyNewState;
  807.         $yytos->major = $yyMajor;
  808.         $yytos->minor = $yypMinor;
  809.         array_push($this->yystack$yytos);
  810.         if (self::$yyTraceFILE && $this->yyidx > 0{
  811.             fprintf(self::$yyTraceFILE"%sShift %d\n"self::$yyTracePrompt,
  812.                 $yyNewState);
  813.             fprintf(self::$yyTraceFILE"%sStack:"self::$yyTracePrompt);
  814.             for($i = 1; $i <= $this->yyidx$i++{
  815.                 fprintf(self::$yyTraceFILE" %s",
  816.                     self::$yyTokenName[$this->yystack[$i]->major]);
  817.             }
  818.             fwrite(self::$yyTraceFILE,"\n");
  819.         }
  820.     }
  821.  
  822.     /**
  823.      * The following table contains information about every rule that
  824.      * is used during the reduce.
  825.      *
  826.      * <pre>
  827.      * array(
  828.      *  array(
  829.      *   int $lhs;         Symbol on the left-hand side of the rule
  830.      *   int $nrhs;     Number of right-hand side symbols in the rule
  831.      *  ),...
  832.      * );
  833.      * </pre>
  834.      */
  835.     static public $yyRuleInfo = array(
  836.   array'lhs' => 28'rhs' => 1 ),
  837.   array'lhs' => 28'rhs' => 2 ),
  838.   array'lhs' => 29'rhs' => 5 ),
  839.   array'lhs' => 30'rhs' => 1 ),
  840.   array'lhs' => 30'rhs' => 1 ),
  841.   array'lhs' => 32'rhs' => 1 ),
  842.   array'lhs' => 32'rhs' => 2 ),
  843.   array'lhs' => 33'rhs' => 1 ),
  844.   array'lhs' => 33'rhs' => 1 ),
  845.   array'lhs' => 33'rhs' => 1 ),
  846.   array'lhs' => 33'rhs' => 1 ),
  847.   array'lhs' => 33'rhs' => 1 ),
  848.   array'lhs' => 33'rhs' => 2 ),
  849.   array'lhs' => 33'rhs' => 2 ),
  850.   array'lhs' => 33'rhs' => 1 ),
  851.   array'lhs' => 33'rhs' => 1 ),
  852.   array'lhs' => 33'rhs' => 1 ),
  853.   array'lhs' => 31'rhs' => 1 ),
  854.   array'lhs' => 31'rhs' => 3 ),
  855.   array'lhs' => 31'rhs' => 4 ),
  856.   array'lhs' => 31'rhs' => 1 ),
  857.   array'lhs' => 31'rhs' => 2 ),
  858.   array'lhs' => 31'rhs' => 1 ),
  859.   array'lhs' => 31'rhs' => 0 ),
  860.   array'lhs' => 34'rhs' => 3 ),
  861.   array'lhs' => 34'rhs' => 4 ),
  862.   array'lhs' => 34'rhs' => 3 ),
  863.   array'lhs' => 34'rhs' => 2 ),
  864.   array'lhs' => 34'rhs' => 1 ),
  865.   array'lhs' => 36'rhs' => 4 ),
  866.   array'lhs' => 36'rhs' => 5 ),
  867.   array'lhs' => 35'rhs' => 2 ),
  868.   array'lhs' => 35'rhs' => 4 ),
  869.   array'lhs' => 37'rhs' => 1 ),
  870.   array'lhs' => 37'rhs' => 1 ),
  871.   array'lhs' => 37'rhs' => 1 ),
  872.   array'lhs' => 37'rhs' => 1 ),
  873.   array'lhs' => 37'rhs' => 1 ),
  874.   array'lhs' => 37'rhs' => 3 ),
  875.   array'lhs' => 37'rhs' => 1 ),
  876.     );
  877.  
  878.     /**
  879.      * The following table contains a mapping of reduce action to method name
  880.      * that handles the reduction.
  881.      * 
  882.      * If a rule is not set, it has no handler.
  883.      */
  884.     static public $yyReduceMap = array(
  885.         2 => 2,
  886.         3 => 3,
  887.         4 => 4,
  888.         5 => 4,
  889.         36 => 4,
  890.         6 => 6,
  891.         7 => 7,
  892.         8 => 8,
  893.         9 => 9,
  894.         10 => 10,
  895.         11 => 11,
  896.         12 => 12,
  897.         13 => 13,
  898.         14 => 14,
  899.         15 => 15,
  900.         16 => 16,
  901.         18 => 18,
  902.         19 => 19,
  903.         20 => 20,
  904.         21 => 21,
  905.         24 => 24,
  906.         25 => 25,
  907.         26 => 26,
  908.         28 => 26,
  909.         27 => 27,
  910.         29 => 29,
  911.         30 => 30,
  912.         31 => 31,
  913.         32 => 32,
  914.         33 => 33,
  915.         34 => 34,
  916.         35 => 35,
  917.         37 => 37,
  918.         38 => 38,
  919.         39 => 39,
  920.     );
  921.     /* Beginning here are the reduction cases.  A typical example
  922.     ** follows:
  923.     **  #line <lineno> <grammarfile>
  924.     **   function yy_r0($yymsp){ ... }           // User supplied code
  925.     **  #line <lineno> <thisfile>
  926.     */
  927. #line 27 "ProtoParser.y"
  928.     function yy_r2(){
  929.   $this->function->setReturns($this->yystack[$this->yyidx + -4]->minor);
  930.   $this->function->setName($this->yystack[$this->yyidx + -3]->minor);
  931.     }
  932. #line 937 "ProtoParser.php"
  933. #line 32 "ProtoParser.y"
  934.     function yy_r3()$this->_retvalue = array("type" => "void");     }
  935. #line 940 "ProtoParser.php"
  936. #line 33 "ProtoParser.y"
  937.     function yy_r4()$this->_retvalue $this->yystack[$this->yyidx + 0]->minor;     }
  938. #line 943 "ProtoParser.php"
  939. #line 36 "ProtoParser.y"
  940.     function yy_r6()$this->_retvalue $this->yystack[$this->yyidx + -1]->minor; $this->_retvalue["byRef"= true;     }
  941. #line 946 "ProtoParser.php"
  942. #line 38 "ProtoParser.y"
  943.     function yy_r7()$this->_retvalue = array("type" => "bool");     }
  944. #line 949 "ProtoParser.php"
  945. #line 39 "ProtoParser.y"
  946.     function yy_r8()$this->_retvalue = array("type" => "int");     }
  947. #line 952 "ProtoParser.php"
  948. #line 40 "ProtoParser.y"
  949.     function yy_r9()$this->_retvalue = array("type" => "float");     }
  950. #line 955 "ProtoParser.php"
  951. #line 41 "ProtoParser.y"
  952.     function yy_r10()$this->_retvalue = array("type" => "string");     }
  953. #line 958 "ProtoParser.php"
  954. #line 42 "ProtoParser.y"
  955.     function yy_r11()$this->_retvalue = array("type" => "array");     }
  956. #line 961 "ProtoParser.php"
  957. #line 43 "ProtoParser.y"
  958.     function yy_r12()$this->_retvalue = array("type" => "object",   "subtype" => $this->yystack[$this->yyidx + 0]->minor);     }
  959. #line 964 "ProtoParser.php"
  960. #line 44 "ProtoParser.y"
  961.     function yy_r13()$this->_retvalue = array("type" => "resource""subtype" => $this->yystack[$this->yyidx + 0]->minor);     }
  962. #line 967 "ProtoParser.php"
  963. #line 45 "ProtoParser.y"
  964.     function yy_r14()$this->_retvalue = array("type" => "mixed");     }
  965. #line 970 "ProtoParser.php"
  966. #line 46 "ProtoParser.y"
  967.     function yy_r15()$this->_retvalue = array("type" => "callback");     }
  968. #line 973 "ProtoParser.php"
  969. #line 47 "ProtoParser.y"
  970.     function yy_r16()$this->_retvalue = array("type" => "stream");     }
  971. #line 976 "ProtoParser.php"
  972. #line 50 "ProtoParser.y"
  973.     function yy_r18(){
  974.   $this->yystack[$this->yyidx + -1]->minor["optional"= true;
  975.   $stat $this->function->addParam($this->yystack[$this->yyidx + -1]->minor);
  976.   if ($stat !== true{
  977.     throw new Exception($stat->getMessage());
  978.   }
  979.     }
  980. #line 985 "ProtoParser.php"
  981. #line 57 "ProtoParser.y"
  982.     function yy_r19(){
  983.   $this->yystack[$this->yyidx + -2]->minor["optional"= true;
  984.   $stat $this->function->addParam($this->yystack[$this->yyidx + -2]->minor);
  985.   if ($stat !== true{
  986.     throw new Exception($stat->getMessage());
  987.   }
  988.   foreach ($this->optParams as $param{
  989.     $stat $this->function->addParam($param);
  990.     if ($stat !== true{
  991.       throw new Exception($stat->getMessage());
  992.     }
  993.   }
  994.     }
  995. #line 1000 "ProtoParser.php"
  996. #line 70 "ProtoParser.y"
  997.     function yy_r20()
  998.   $this->function->setVarargs(true)
  999.     }
  1000. #line 1005 "ProtoParser.php"
  1001. #line 73 "ProtoParser.y"
  1002.     function yy_r21()
  1003.   $stat $this->function->setVarargsType($this->yystack[$this->yyidx + -1]->minor["type"]);
  1004.   if ($stat !== true{
  1005.     throw new Exception($stat->getMessage());
  1006.   }
  1007.   $this->function->setVarargs(true)
  1008.     }
  1009. #line 1014 "ProtoParser.php"
  1010. #line 83 "ProtoParser.y"
  1011.     function yy_r24()
  1012.   $this->function->setVarargs(true);
  1013.     }
  1014. #line 1019 "ProtoParser.php"
  1015. #line 86 "ProtoParser.y"
  1016.     function yy_r25()
  1017.   $stat $this->function->setVarargsType($this->yystack[$this->yyidx + -1]->minor["type"]);
  1018.   if ($stat !== true{
  1019.     throw new Exception($stat->getMessage());
  1020.   }
  1021.   $this->function->setVarargs(true);
  1022.     }
  1023. #line 1028 "ProtoParser.php"
  1024. #line 93 "ProtoParser.y"
  1025.     function yy_r26(){
  1026.   $stat $this->function->addParam($this->yystack[$this->yyidx + 0]->minor);
  1027.   if ($stat !== true{
  1028.     throw new Exception($stat->getMessage());
  1029.   }
  1030.     }
  1031. #line 1036 "ProtoParser.php"
  1032. #line 99 "ProtoParser.y"
  1033.     function yy_r27(){
  1034.   foreach ($this->optParams as $param{
  1035.     $stat $this->function->addParam($param);
  1036.     if ($stat !== true{
  1037.       throw new Exception($stat->getMessage());
  1038.     }
  1039.   }
  1040.     }
  1041. #line 1046 "ProtoParser.php"
  1042. #line 113 "ProtoParser.y"
  1043.     function yy_r29(){
  1044.   $this->yystack[$this->yyidx + -1]->minor["optional"= true;
  1045.   array_unshift($this->optParams$this->yystack[$this->yyidx + -1]->minor);
  1046.     }
  1047. #line 1052 "ProtoParser.php"
  1048. #line 117 "ProtoParser.y"
  1049.     function yy_r30(){
  1050.   $this->yystack[$this->yyidx + -2]->minor["optional"= true;
  1051.   array_unshift($this->optParams$this->yystack[$this->yyidx + -2]->minor);
  1052.     }
  1053. #line 1058 "ProtoParser.php"
  1054. #line 122 "ProtoParser.y"
  1055.     function yy_r31(){
  1056.   $this->_retvalue $this->yystack[$this->yyidx + -1]->minor;
  1057.   $this->_retvalue["name"$this->yystack[$this->yyidx + 0]->minor;
  1058.     }
  1059. #line 1064 "ProtoParser.php"
  1060. #line 126 "ProtoParser.y"
  1061.     function yy_r32(){
  1062.   $this->_retvalue $this->yystack[$this->yyidx + -3]->minor;
  1063.   $this->_retvalue["name"]     $this->yystack[$this->yyidx + -2]->minor;
  1064.   $this->_retvalue["default"]  $this->yystack[$this->yyidx + 0]->minor;        
  1065.   $this->_retvalue["optional"= true;
  1066.     }
  1067. #line 1072 "ProtoParser.php"
  1068. #line 133 "ProtoParser.y"
  1069.     function yy_r33()$this->_retvalue "true";     }
  1070. #line 1075 "ProtoParser.php"
  1071. #line 134 "ProtoParser.y"
  1072.     function yy_r34()$this->_retvalue "false";     }
  1073. #line 1078 "ProtoParser.php"
  1074. #line 135 "ProtoParser.y"
  1075.     function yy_r35()$this->_retvalue "null";     }
  1076. #line 1081 "ProtoParser.php"
  1077. #line 137 "ProtoParser.y"
  1078.     function yy_r37()$this->_retvalue '"'.$this->yystack[$this->yyidx + 0]->minor.'"';     }
  1079. #line 1084 "ProtoParser.php"
  1080. #line 138 "ProtoParser.y"
  1081.     function yy_r38()$this->_retvalue "array()";     }
  1082. #line 1087 "ProtoParser.php"
  1083. #line 139 "ProtoParser.y"
  1084.     function yy_r39()
  1085.     $constant $this->extension->getConstant($this->yystack[$this->yyidx + 0]->minor);
  1086.     if ($constant{
  1087.         $this->_retvalue $constant;
  1088.     else {
  1089.         throw new Exception("invalid default value '".$this->yystack[$this->yyidx + 0]->minor."'");
  1090.     }
  1091.     }
  1092. #line 1097 "ProtoParser.php"
  1093.  
  1094.     /**
  1095.      * placeholder for the left hand side in a reduce operation.
  1096.      * 
  1097.      * For a parser with a rule like this:
  1098.      * <pre>
  1099.      * rule(A) ::= B. { A = 1; }
  1100.      * </pre>
  1101.      * 
  1102.      * The parser will translate to something like:
  1103.      * 
  1104.      * <code>
  1105.      * function yy_r0(){$this->_retvalue = 1;}
  1106.      * </code>
  1107.      */
  1108.     private $_retvalue;
  1109.  
  1110.     /**
  1111.      * Perform a reduce action and the shift that must immediately
  1112.      * follow the reduce.
  1113.      * 
  1114.      * For a rule such as:
  1115.      * 
  1116.      * <pre>
  1117.      * A ::= B blah C. { dosomething(); }
  1118.      * </pre>
  1119.      * 
  1120.      * This function will first call the action, if any, ("dosomething();" in our
  1121.      * example), and then it will pop three states from the stack,
  1122.      * one for each entry on the right-hand side of the expression
  1123.      * (B, blah, and C in our example rule), and then push the result of the action
  1124.      * back on to the stack with the resulting state reduced to (as described in the .out
  1125.      * file)
  1126.      * @param int Number of the rule by which to reduce
  1127.      */
  1128.     function yy_reduce($yyruleno)
  1129.     {
  1130.         //int $yygoto;                     /* The next state */
  1131.         //int $yyact;                      /* The next action */
  1132.         //mixed $yygotominor;        /* The LHS of the rule reduced */
  1133.         //CodeGen_PECL_Tools_ProtoParser_yyStackEntry $yymsp;            /* The top of the parser's stack */
  1134.         //int $yysize;                     /* Amount to pop the stack */
  1135.         $yymsp $this->yystack[$this->yyidx];
  1136.         if (self::$yyTraceFILE && $yyruleno >= 0 
  1137.               && $yyruleno < count(self::$yyRuleName)) {
  1138.             fprintf(self::$yyTraceFILE"%sReduce (%d) [%s].\n",
  1139.                 self::$yyTracePrompt$yyruleno,
  1140.                 self::$yyRuleName[$yyruleno]);
  1141.         }
  1142.  
  1143.         $this->_retvalue $yy_lefthand_side = null;
  1144.         if (array_key_exists($yyrulenoself::$yyReduceMap)) {
  1145.             // call the action
  1146.             $this->_retvalue = null;
  1147.             $this->{'yy_r' . self::$yyReduceMap[$yyruleno]}();
  1148.             $yy_lefthand_side $this->_retvalue;
  1149.         }
  1150.         $yygoto = self::$yyRuleInfo[$yyruleno]['lhs'];
  1151.         $yysize = self::$yyRuleInfo[$yyruleno]['rhs'];
  1152.         $this->yyidx -= $yysize;
  1153.         for($i $yysize$i$i--{
  1154.             // pop all of the right-hand side parameters
  1155.             array_pop($this->yystack);
  1156.         }
  1157.         $yyact $this->yy_find_reduce_action($this->yystack[$this->yyidx]->stateno$yygoto);
  1158.         if ($yyact < self::YYNSTATE{
  1159.             /* If we are not debugging and the reduce action popped at least
  1160.             ** one element off the stack, then we can push the new element back
  1161.             ** onto the stack here, and skip the stack overflow test in yy_shift().
  1162.             ** That gives a significant speed improvement. */
  1163.             if (!self::$yyTraceFILE && $yysize{
  1164.                 $this->yyidx++;
  1165.                 $x = new CodeGen_PECL_Tools_ProtoParser_yyStackEntry;
  1166.                 $x->stateno = $yyact;
  1167.                 $x->major = $yygoto;
  1168.                 $x->minor = $yy_lefthand_side;
  1169.                 $this->yystack[$this->yyidx$x;
  1170.             else {
  1171.                 $this->yy_shift($yyact$yygoto$yy_lefthand_side);
  1172.             }
  1173.         elseif ($yyact == self::YYNSTATE + self::YYNRULE + 1{
  1174.             $this->yy_accept();
  1175.         }
  1176.     }
  1177.  
  1178.     /**
  1179.      * The following code executes when the parse fails
  1180.      * 
  1181.      * Code from %parse_fail is inserted here
  1182.      */
  1183.     function yy_parse_failed()
  1184.     {
  1185.         if (self::$yyTraceFILE{
  1186.             fprintf(self::$yyTraceFILE"%sFail!\n"self::$yyTracePrompt);
  1187.         }
  1188.         while ($this->yyidx >= 0{
  1189.             $this->yy_pop_parser_stack();
  1190.         }
  1191.         /* Here code is inserted which will be executed whenever the
  1192.         ** parser fails */
  1193.     }
  1194.  
  1195.     /**
  1196.      * The following code executes when a syntax error first occurs.
  1197.      * 
  1198.      * %syntax_error code is inserted here
  1199.      * @param int The major type of the error token
  1200.      * @param mixed The minor type of the error token
  1201.      */
  1202.     function yy_syntax_error($yymajor$TOKEN)
  1203.     {
  1204. #line 15 "ProtoParser.y"
  1205.  
  1206.   $expect = array();
  1207.   foreach ($this->yy_get_expected_tokens($yymajoras $token{
  1208.     $expect[= self::$yyTokenName[$token];
  1209.   }
  1210.   throw new Exception('Unexpected ' $this->tokenName($yymajor'(' $TOKEN
  1211.                       . '), expected one of: ' implode(','$expect));
  1212. #line 1218 "ProtoParser.php"
  1213.     }
  1214.  
  1215.     /**
  1216.      * The following is executed when the parser accepts
  1217.      * 
  1218.      * %parse_accept code is inserted here
  1219.      */
  1220.     function yy_accept()
  1221.     {
  1222.         if (self::$yyTraceFILE{
  1223.             fprintf(self::$yyTraceFILE"%sAccept!\n"self::$yyTracePrompt);
  1224.         }
  1225.         while ($this->yyidx >= 0{
  1226.             $stack $this->yy_pop_parser_stack();
  1227.         }
  1228.         /* Here code is inserted which will be executed whenever the
  1229.         ** parser accepts */
  1230.     }
  1231.  
  1232.     /**
  1233.      * The main parser program.
  1234.      * 
  1235.      * The first argument is the major token number.  The second is
  1236.      * the token value string as scanned from the input.
  1237.      *
  1238.      * @param int the token number
  1239.      * @param mixed the token value
  1240.      * @param mixed any extra arguments that should be passed to handlers
  1241.      */
  1242.     function doParse($yymajor$yytokenvalue)
  1243.     {
  1244. //        $yyact;            /* The parser action. */
  1245. //        $yyendofinput;     /* True if we are at the end of input */
  1246.         $yyerrorhit = 0;   /* True if yymajor has invoked an error */
  1247.         
  1248.         /* (re)initialize the parser, if necessary */
  1249.         if ($this->yyidx === null || $this->yyidx < 0{
  1250.             /* if ($yymajor == 0) return; // not sure why this was here... */
  1251.             $this->yyidx = 0;
  1252.             $this->yyerrcnt = -1;
  1253.             $x = new CodeGen_PECL_Tools_ProtoParser_yyStackEntry;
  1254.             $x->stateno = 0;
  1255.             $x->major = 0;
  1256.             $this->yystack = array();
  1257.             array_push($this->yystack$x);
  1258.         }
  1259.         $yyendofinput ($yymajor==0);
  1260.         
  1261.         if (self::$yyTraceFILE{
  1262.             fprintf(self::$yyTraceFILE"%sInput %s\n",
  1263.                 self::$yyTracePromptself::$yyTokenName[$yymajor]);
  1264.         }
  1265.         
  1266.         do {
  1267.             $yyact $this->yy_find_shift_action($yymajor);
  1268.             if ($yymajor < self::YYERRORSYMBOL &&
  1269.                   !$this->yy_is_expected_token($yymajor)) {
  1270.                 // force a syntax error
  1271.                 $yyact = self::YY_ERROR_ACTION;
  1272.             }
  1273.             if ($yyact < self::YYNSTATE{
  1274.                 $this->yy_shift($yyact$yymajor$yytokenvalue);
  1275.                 $this->yyerrcnt--;
  1276.                 if ($yyendofinput && $this->yyidx >= 0{
  1277.                     $yymajor = 0;
  1278.                 else {
  1279.                     $yymajor = self::YYNOCODE;
  1280.                 }
  1281.             elseif ($yyact < self::YYNSTATE + self::YYNRULE{
  1282.                 $this->yy_reduce($yyact - self::YYNSTATE);
  1283.             elseif ($yyact == self::YY_ERROR_ACTION{
  1284.                 if (self::$yyTraceFILE{
  1285.                     fprintf(self::$yyTraceFILE"%sSyntax Error!\n",
  1286.                         self::$yyTracePrompt);
  1287.                 }
  1288.                 if (self::YYERRORSYMBOL{
  1289.                     /* A syntax error has occurred.
  1290.                     ** The response to an error depends upon whether or not the
  1291.                     ** grammar defines an error token "ERROR".  
  1292.                     **
  1293.                     ** This is what we do if the grammar does define ERROR:
  1294.                     **
  1295.                     **  * Call the %syntax_error function.
  1296.                     **
  1297.                     **  * Begin popping the stack until we enter a state where
  1298.                     **    it is legal to shift the error symbol, then shift
  1299.                     **    the error symbol.
  1300.                     **
  1301.                     **  * Set the error count to three.
  1302.                     **
  1303.                     **  * Begin accepting and shifting new tokens.  No new error
  1304.                     **    processing will occur until three tokens have been
  1305.                     **    shifted successfully.
  1306.                     **
  1307.                     */
  1308.                     if ($this->yyerrcnt < 0{
  1309.                         $this->yy_syntax_error($yymajor$yytokenvalue);
  1310.                     }
  1311.                     $yymx $this->yystack[$this->yyidx]->major;
  1312.                     if ($yymx == self::YYERRORSYMBOL || $yyerrorhit ){
  1313.                         if (self::$yyTraceFILE{
  1314.                             fprintf(self::$yyTraceFILE"%sDiscard input token %s\n",
  1315.                                 self::$yyTracePromptself::$yyTokenName[$yymajor]);
  1316.                         }
  1317.                         $this->yy_destructor($yymajor$yytokenvalue);
  1318.                         $yymajor = self::YYNOCODE;
  1319.                     else {
  1320.                         while ($this->yyidx >= 0 &&
  1321.                                  $yymx != self::YYERRORSYMBOL &&
  1322.         ($yyact $this->yy_find_shift_action(self::YYERRORSYMBOL)) >= self::YYNSTATE
  1323.                               ){
  1324.                             $this->yy_pop_parser_stack();
  1325.                         }
  1326.                         if ($this->yyidx < 0 || $yymajor==0{
  1327.                             $this->yy_destructor($yymajor$yytokenvalue);
  1328.                             $this->yy_parse_failed();
  1329.                             $yymajor = self::YYNOCODE;
  1330.                         elseif ($yymx != self::YYERRORSYMBOL{
  1331.                             $u2 = 0;
  1332.                             $this->yy_shift($yyactself::YYERRORSYMBOL$u2);
  1333.                         }
  1334.                     }
  1335.                     $this->yyerrcnt = 3;
  1336.                     $yyerrorhit = 1;
  1337.                 else {
  1338.                     /* YYERRORSYMBOL is not defined */
  1339.                     /* This is what we do if the grammar does not define ERROR:
  1340.                     **
  1341.                     **  * Report an error message, and throw away the input token.
  1342.                     **
  1343.                     **  * If the input token is $, then fail the parse.
  1344.                     **
  1345.                     ** As before, subsequent error messages are suppressed until
  1346.                     ** three input tokens have been successfully shifted.
  1347.                     */
  1348.                     if ($this->yyerrcnt <= 0{
  1349.                         $this->yy_syntax_error($yymajor$yytokenvalue);
  1350.                     }
  1351.                     $this->yyerrcnt = 3;
  1352.                     $this->yy_destructor($yymajor$yytokenvalue);
  1353.                     if ($yyendofinput{
  1354.                         $this->yy_parse_failed();
  1355.                     }
  1356.                     $yymajor = self::YYNOCODE;
  1357.                 }
  1358.             else {
  1359.                 $this->yy_accept();
  1360.                 $yymajor = self::YYNOCODE;
  1361.             }            
  1362.         while ($yymajor != self::YYNOCODE && $this->yyidx >= 0);
  1363.     }
  1364. }

Documentation generated on Mon, 11 Mar 2019 15:39:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.