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("\n"$this->value);
  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("\n"$this->value);
  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 => "^(\\()|^(\\))|^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  108.         2 => "^(\\))|^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  109.         3 => "^(\\[)|^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  110.         4 => "^(\\])|^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  111.         5 => "^(=)|^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  112.         6 => "^(,)|^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  113.         7 => "^(;)|^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  114.         8 => "^(\\.\\.\\.)|^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  115.         9 => "^([&@])|^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  116.         10 => "^([_a-zA-Z][_a-zA-Z0-9]*)|^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  117.         11 => "^(\"[^\"]*\"|'[^']*')|^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  118.         12 => "^([0-9]*(\\.[0-9]+)?([eE][+-]?[0-9]+)?)|^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  119.         13 => "^([+-]?[0-9]+)|^(0x[0-9a-fA-F]+)",
  120.         16 => "^(0x[0-9a-fA-F]+)",
  121.         17 => "",
  122.     );
  123.  
  124.                     // yymore is needed
  125.                     do {
  126.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  127.                             throw new Exception('cannot do yymore for the last token');
  128.                         }
  129.                         if (preg_match($yy_yymore_patterns[$this->token],
  130.                               substr($this->data$this->count)$yymatches)) {
  131.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  132.                             next($yymatches)// skip global match
  133.                             $this->token key($yymatches)// token number
  134.                             $this->value current($yymatches)// token value
  135.                             $this->line substr_count("\n"$this->value);
  136.                         }
  137.                     while ($this->{'yy_r1_' $this->token}(!== null);
  138.                     // accept
  139.                     $this->count += strlen($this->value);
  140.                     $this->line += substr_count("\n"$this->value);
  141.                     return true;
  142.                 }
  143.             else {
  144.                 throw new Exception('Unexpected input at line' $this->line .
  145.                     ': ' $this->data[$this->count]);
  146.             }
  147.             break;
  148.         while (true);
  149.     // end function
  150.  
  151.     function yy_r1_1($yy_subpatterns)
  152.     {
  153.  
  154.     return false;
  155.     }
  156.     function yy_r1_2($yy_subpatterns)
  157.     {
  158.  
  159.     $this->token = CodeGen_PECL_Tools_ProtoParser::PAR_OPEN;
  160.     }
  161.     function yy_r1_3($yy_subpatterns)
  162.     {
  163.  
  164.     $this->token = CodeGen_PECL_Tools_ProtoParser::PAR_CLOSE;
  165.     }
  166.     function yy_r1_4($yy_subpatterns)
  167.     {
  168.  
  169.     $this->token = CodeGen_PECL_Tools_ProtoParser::SQUARE_OPEN;
  170.     }
  171.     function yy_r1_5($yy_subpatterns)
  172.     {
  173.  
  174.     $this->token = CodeGen_PECL_Tools_ProtoParser::SQUARE_CLOSE;
  175.     }
  176.     function yy_r1_6($yy_subpatterns)
  177.     {
  178.  
  179.     $this->token = CodeGen_PECL_Tools_ProtoParser::EQ;
  180.     }
  181.     function yy_r1_7($yy_subpatterns)
  182.     {
  183.  
  184.     $this->token = CodeGen_PECL_Tools_ProtoParser::COMMA;
  185.     }
  186.     function yy_r1_8($yy_subpatterns)
  187.     {
  188.  
  189.     $this->token = CodeGen_PECL_Tools_ProtoParser::SEMICOLON;
  190.     }
  191.     function yy_r1_9($yy_subpatterns)
  192.     {
  193.  
  194.     $this->token = CodeGen_PECL_Tools_ProtoParser::ELLIPSE;
  195.     }
  196.     function yy_r1_10($yy_subpatterns)
  197.     {
  198.  
  199.     $this->token = CodeGen_PECL_Tools_ProtoParser::AMPERSAND;
  200.     }
  201.     function yy_r1_11($yy_subpatterns)
  202.     {
  203.  
  204.     switch ($this->value{
  205.     case "void":
  206.         $this->token = CodeGen_PECL_Tools_ProtoParser::VOID;
  207.         break;
  208.     case "bool":     
  209.     case "boolean":
  210.         $this->token = CodeGen_PECL_Tools_ProtoParser::BOOL;
  211.         break;
  212.     case "int"
  213.     case "integer":
  214.     case "long":
  215.         $this->token = CodeGen_PECL_Tools_ProtoParser::INT;
  216.         break;
  217.     case "float":
  218.     case "double":
  219.         $this->token = CodeGen_PECL_Tools_ProtoParser::FLOAT;
  220.         break;
  221.     case "string"
  222.         $this->token = CodeGen_PECL_Tools_ProtoParser::STRING;
  223.         break;
  224.     case "array"
  225.         $this->token = CodeGen_PECL_Tools_ProtoParser::ARRAY_;
  226.         break;
  227.     case "class":
  228.     case "object":
  229.         $this->token = CodeGen_PECL_Tools_ProtoParser::CLASS_;
  230.         break;
  231.     case "resource"
  232.         $this->token = CodeGen_PECL_Tools_ProtoParser::RESOURCE;
  233.         break;
  234.     case "mixed"
  235.         $this->token = CodeGen_PECL_Tools_ProtoParser::MIXED;
  236.         break;
  237.     case "callback"
  238.         $this->token = CodeGen_PECL_Tools_ProtoParser::CALLBACK;
  239.         break;
  240.     case "stream"
  241.         $this->token = CodeGen_PECL_Tools_ProtoParser::STREAM;
  242.         break;
  243.     case "true"
  244.         $this->token = CodeGen_PECL_Tools_ProtoParser::TRUE_;
  245.         break;
  246.     case "false":
  247.         $this->token = CodeGen_PECL_Tools_ProtoParser::FALSE_;
  248.         break;
  249.     case "null"
  250.         $this->token = CodeGen_PECL_Tools_ProtoParser::NULL_;
  251.         break;
  252.     default:
  253.         $this->token = CodeGen_PECL_Tools_ProtoParser::NAME;
  254.         break;
  255.     }
  256.     }
  257.     function yy_r1_12($yy_subpatterns)
  258.     {
  259.  
  260.     $this->token = CodeGen_PECL_Tools_ProtoParser::STRVAL;
  261.     }
  262.     function yy_r1_13($yy_subpatterns)
  263.     {
  264.  
  265.     $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  266.     }
  267.     function yy_r1_16($yy_subpatterns)
  268.     {
  269.  
  270.     $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  271.     }
  272.     function yy_r1_17($yy_subpatterns)
  273.     {
  274.  
  275.     $this->token = CodeGen_PECL_Tools_ProtoParser::NUMVAL;
  276.     }
  277.  
  278. }

Documentation generated on Mon, 11 Mar 2019 14:44:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.