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

Source for file ProtoLexer.php

Documentation is available at ProtoLexer.php

  1. <?php
  2. class CodeGen_PECL_Tools_ProtoLexer
  3. {
  4.     private $data;
  5.     public $token;
  6.     public $value;
  7.     private $line;
  8.     private $count;
  9.  
  10.     function __construct($data)
  11.     {
  12.         $this->data  $data;
  13.         $this->count = 0;
  14.         $this->line  = 1;
  15.     }
  16.  
  17.  
  18.     private $_yy_state = 1;
  19.     private $_yy_stack = array();
  20.  
  21.     function yylex()
  22.     {
  23.         return $this->{'yylex' $this->_yy_state}();
  24.     }
  25.  
  26.     function yypushstate($state)
  27.     {
  28.         array_push($this->_yy_stack$this->_yy_state);
  29.         $this->_yy_state $state;
  30.     }
  31.  
  32.     function yypopstate()
  33.     {
  34.         $this->_yy_state array_pop($this->_yy_stack);
  35.     }
  36.  
  37.     function yybegin($state)
  38.     {
  39.         $this->_yy_state $state;
  40.     }
  41.  
  42.  
  43.  
  44.  
  45.     function yylex1()
  46.     {
  47.         $tokenMap = array (
  48.               1 => 0,
  49.               2 => 0,
  50.               3 => 0,
  51.               4 => 0,
  52.               5 => 0,
  53.               6 => 0,
  54.               7 => 0,
  55.               8 => 0,
  56.               9 => 0,
  57.               10 => 0,
  58.               11 => 0,
  59.               12 => 0,
  60.               13 => 2,
  61.               16 => 0,
  62.               17 => 0,
  63.             );
  64.         if ($this->count >= strlen($this->data)) {
  65.             return false; // end of input
  66.         }
  67.         $yy_global_pattern "/^([ \t\n]+)|^(\\()|^(\\))|^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)/";
  68.  
  69.         do {
  70.             if (preg_match($yy_global_patternsubstr($this->data$this->count)$yymatches)) {
  71.                 $yysubmatches $yymatches;
  72.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  73.                 if (!count($yymatches)) {
  74.                     throw new Exception('Error: lexing failed because a rule matched' .
  75.                         'an empty string.  Input "' substr($this->data,
  76.                         $this->count5'... state 1');
  77.                 }
  78.                 next($yymatches)// skip global match
  79.                 $this->token key($yymatches)// token number
  80.                 if ($tokenMap[$this->token]{
  81.                     // extract sub-patterns for passing to lex function
  82.                     $yysubmatches array_slice($yysubmatches$this->token + 1,
  83.                         $tokenMap[$this->token]);
  84.                 else {
  85.                     $yysubmatches = array();
  86.                 }
  87.                 $this->value current($yymatches)// token value
  88.                 $r $this->{'yy_r1_' $this->token}($yysubmatches);
  89.                 if ($r === null{
  90.                     $this->count += strlen($this->value);
  91.                     $this->line += substr_count($this->value"\n");
  92.                     // accept this token
  93.                     return true;
  94.                 elseif ($r === true{
  95.                     // we have changed state
  96.                     // process this token in the new state
  97.                     return $this->yylex();
  98.                 elseif ($r === false{
  99.                     $this->count += strlen($this->value);
  100.                     $this->line += substr_count($this->value"\n");
  101.                     if ($this->count >= strlen($this->data)) {
  102.                         return false; // end of input
  103.                     }
  104.                     // skip this token
  105.                     continue;
  106.                 else {                    $yy_yymore_patterns = array(
  107.         1 => array(0"^(\\()|^(\\))|^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  108.         2 => array(0"^(\\))|^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  109.         3 => array(0"^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  110.         4 => array(0"^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  111.         5 => array(0"^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  112.         6 => array(0"^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  113.         7 => array(0"^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  114.         8 => array(0"^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  115.         9 => array(0"^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  116.         10 => array(0"^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  117.         11 => array(0"^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  118.         12 => array(0"^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  119.         13 => array(2"^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)"),
  120.         16 => array(2"^(0x[0-9a-fA-F]+)"),
  121.         17 => array(2""),
  122.     );
  123.  
  124.                     // yymore is needed
  125.                     do {
  126.                         if (!strlen($yy_yymore_patterns[$this->token][1])) {
  127.                             throw new Exception('cannot do yymore for the last token');
  128.                         }
  129.                         $yysubmatches = array();
  130.                         if (preg_match('/' $yy_yymore_patterns[$this->token][1'/',
  131.                               substr($this->data$this->count)$yymatches)) {
  132.                             $yysubmatches $yymatches;
  133.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  134.                             next($yymatches)// skip global match
  135.                             $this->token += key($yymatches$yy_yymore_patterns[$this->token][0]// token number
  136.                             $this->value current($yymatches)// token value
  137.                             $this->line substr_count($this->value"\n");
  138.                             if ($tokenMap[$this->token]{
  139.                                 // extract sub-patterns for passing to lex function
  140.                                 $yysubmatches array_slice($yysubmatches$this->token + 1,
  141.                                     $tokenMap[$this->token]);
  142.                             else {
  143.                                 $yysubmatches = array();
  144.                             }
  145.                         }
  146.                         $r $this->{'yy_r1_' $this->token}($yysubmatches);
  147.                     while ($r !== null && !is_bool($r));
  148.                     if ($r === true{
  149.                         // we have changed state
  150.                         // process this token in the new state
  151.                         return $this->yylex();
  152.                     elseif ($r === false{
  153.                         $this->count += strlen($this->value);
  154.                         $this->line += substr_count($this->value"\n");
  155.                         if ($this->count >= strlen($this->data)) {
  156.                             return false; // end of input
  157.                         }
  158.                         // skip this token
  159.                         continue;
  160.                     else {
  161.                         // accept
  162.                         $this->count += strlen($this->value);
  163.                         $this->line += substr_count($this->value"\n");
  164.                         return true;
  165.                     }
  166.                 }
  167.             else {
  168.                 throw new Exception('Unexpected input at line' $this->line .
  169.                     ': ' $this->data[$this->count]);
  170.             }
  171.             break;
  172.         while (true);
  173.  
  174.     // end function
  175.  
  176.     function yy_r1_1($yy_subpatterns)
  177.     {
  178.  
  179.     return false;
  180.     }
  181.     function yy_r1_2($yy_subpatterns)
  182.     {
  183.  
  184.     $this->token = CodeGen_PECL_Tools_ProtoParser::PAR_OPEN;
  185.     }
  186.     function yy_r1_3($yy_subpatterns)
  187.     {
  188.  
  189.     $this->token = CodeGen_PECL_Tools_ProtoParser::PAR_CLOSE;
  190.     }
  191.     function yy_r1_4($yy_subpatterns)
  192.     {
  193.  
  194.     $this->token = CodeGen_PECL_Tools_ProtoParser::SQUARE_OPEN;
  195.     }
  196.     function yy_r1_5($yy_subpatterns)
  197.     {
  198.  
  199.     $this->token = CodeGen_PECL_Tools_ProtoParser::SQUARE_CLOSE;
  200.     }
  201.     function yy_r1_6($yy_subpatterns)
  202.     {
  203.  
  204.     $this->token = CodeGen_PECL_Tools_ProtoParser::EQ;
  205.     }
  206.     function yy_r1_7($yy_subpatterns)
  207.     {
  208.  
  209.     $this->token = CodeGen_PECL_Tools_ProtoParser::COMMA;
  210.     }
  211.     function yy_r1_8($yy_subpatterns)
  212.     {
  213.  
  214.     $this->token = CodeGen_PECL_Tools_ProtoParser::SEMICOLON;
  215.     }
  216.     function yy_r1_9($yy_subpatterns)
  217.     {
  218.  
  219.     $this->token = CodeGen_PECL_Tools_ProtoParser::ELLIPSE;
  220.     }
  221.     function yy_r1_10($yy_subpatterns)
  222.     {
  223.  
  224.     $this->token = CodeGen_PECL_Tools_ProtoParser::AMPERSAND;
  225.     }
  226.     function yy_r1_11($yy_subpatterns)
  227.     {
  228.  
  229.     switch ($this->value{
  230.     case "void":
  231.         $this->token = CodeGen_PECL_Tools_ProtoParser::VOID;
  232.         break;
  233.     case "bool":     
  234.     case "boolean":
  235.         $this->token = CodeGen_PECL_Tools_ProtoParser::BOOL;
  236.         break;
  237.     case "int"
  238.     case "integer":
  239.     case "long":
  240.         $this->token = CodeGen_PECL_Tools_ProtoParser::INT;
  241.         break;
  242.     case "float":
  243.     case "double":
  244.         $this->token = CodeGen_PECL_Tools_ProtoParser::FLOAT;
  245.         break;
  246.     case "string"
  247.         $this->token = CodeGen_PECL_Tools_ProtoParser::STRING;
  248.         break;
  249.     case "array"
  250.         $this->token = CodeGen_PECL_Tools_ProtoParser::ARRAY_;
  251.         break;
  252.     case "class":
  253.     case "object":
  254.         $this->token = CodeGen_PECL_Tools_ProtoParser::CLASS_;
  255.         break;
  256.     case "resource"
  257.         $this->token = CodeGen_PECL_Tools_ProtoParser::RESOURCE;
  258.         break;
  259.     case "mixed"
  260.         $this->token = CodeGen_PECL_Tools_ProtoParser::MIXED;
  261.         break;
  262.     case "callback"
  263.         $this->token = CodeGen_PECL_Tools_ProtoParser::CALLBACK;
  264.         break;
  265.     case "stream"
  266.         $this->token = CodeGen_PECL_Tools_ProtoParser::STREAM;
  267.         break;
  268.     case "true"
  269.         $this->token = CodeGen_PECL_Tools_ProtoParser::TRUE_;
  270.         break;
  271.     case "false":
  272.         $this->token = CodeGen_PECL_Tools_ProtoParser::FALSE_;
  273.         break;
  274.     case "null"
  275.         $this->token = CodeGen_PECL_Tools_ProtoParser::NULL_;
  276.         break;
  277.     default:
  278.         $this->token = CodeGen_PECL_Tools_ProtoParser::NAME;
  279.         break;
  280.     }
  281.     }
  282.     function yy_r1_12($yy_subpatterns)
  283.     {
  284.  
  285.     $this->token = CodeGen_PECL_Tools_ProtoParser::STRVAL;
  286.     }
  287.     function yy_r1_13($yy_subpatterns)
  288.     {
  289.  
  290.     $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  291.     }
  292.     function yy_r1_16($yy_subpatterns)
  293.     {
  294.  
  295.     $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  296.     }
  297.     function yy_r1_17($yy_subpatterns)
  298.     {
  299.  
  300.     $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  301.     }
  302.  
  303. }

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