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

Source for file Lexer.php

Documentation is available at Lexer.php

  1. <?php
  2. //require_once 'File/ChessPGN/Parser.php';
  3. require_once dirname(__FILE__'/Parser.php';
  4.  
  5. class File_ChessPGN_Lexer
  6. {
  7.     const TAGOPEN = File_ChessPGN_Parser::TAGOPEN; // [
  8.     const TAGNAME = File_ChessPGN_Parser::TAGNAME; // ]
  9.     const TAGCLOSE = File_ChessPGN_Parser::TAGCLOSE; // ]
  10.     const STRING = File_ChessPGN_Parser::STRING; // ]
  11.     const NAG = File_ChessPGN_Parser::NAG; // $1 $2, etc.
  12.     const GAMEEND = File_ChessPGN_Parser::GAMEEND; // * 1-0 0-1
  13.     const PAWNMOVE = File_ChessPGN_Parser::PAWNMOVE; // e4, e8=Q, exd8=R
  14.     const PIECEMOVE = File_ChessPGN_Parser::PIECEMOVE; // Nf2, Nab2, N3d5, Qxe4, Qexe4, Q3xe4
  15.     const PLACEMENTMOVE = File_ChessPGN_Parser::PLACEMENTMOVE; // N@f2, P@d5
  16.     const CHECK = File_ChessPGN_Parser::CHECK; // +
  17.     const MATE = File_ChessPGN_Parser::MATE; // #
  18.     const DIGIT = File_ChessPGN_Parser::DIGIT; // 0-9
  19.     const MOVEANNOT = File_ChessPGN_Parser::MOVEANNOT; // ! ? !! ?? !? ?!
  20.     const RAVOPEN = File_ChessPGN_Parser::RAVOPEN; // (
  21.     const RAVCLOSE = File_ChessPGN_Parser::RAVCLOSE; // )
  22.     const PERIOD = File_ChessPGN_Parser::PERIOD; // .
  23.     const COMMENTOPEN = File_ChessPGN_Parser::COMMENTOPEN; // {
  24.     const COMMENTCLOSE = File_ChessPGN_Parser::COMMENTCLOSE; // }
  25.     const COMMENT = File_ChessPGN_Parser::COMMENT; // anything
  26.     const CASTLE = File_ChessPGN_Parser::CASTLE; // O-O O-O-O
  27.  
  28.     private $input;
  29.     private $N;
  30.     public $token;
  31.     public $value;
  32.     public $line;
  33.     private $_string;
  34.     private $debug = 0;
  35.     
  36.     function __construct($data)
  37.     {
  38.         $this->input str_replace("\r\n""\n"$data);
  39.         $this->= 0;
  40.     }
  41.  
  42.  
  43.     private $_yy_state = 1;
  44.     private $_yy_stack = array();
  45.  
  46.     function yylex()
  47.     {
  48.         return $this->{'yylex' $this->_yy_state}();
  49.     }
  50.  
  51.     function yypushstate($state)
  52.     {
  53.         array_push($this->_yy_stack$this->_yy_state);
  54.         $this->_yy_state $state;
  55.     }
  56.  
  57.     function yypopstate()
  58.     {
  59.         $this->_yy_state array_pop($this->_yy_stack);
  60.     }
  61.  
  62.     function yybegin($state)
  63.     {
  64.         $this->_yy_state $state;
  65.     }
  66.  
  67.  
  68.  
  69.     function yylex1()
  70.     {
  71.         $tokenMap = array (
  72.               1 => 0,
  73.               2 => 0,
  74.               3 => 0,
  75.               4 => 0,
  76.               5 => 0,
  77.               6 => 0,
  78.               7 => 0,
  79.               8 => 0,
  80.               9 => 0,
  81.               10 => 0,
  82.             );
  83.         if ($this->>= strlen($this->input)) {
  84.             return false; // end of input
  85.         }
  86.         $yy_global_pattern "/^(\\[)|^(\\()|^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)/";
  87.  
  88.         do {
  89.             if (preg_match($yy_global_patternsubstr($this->input$this->N)$yymatches)) {
  90.                 $yysubmatches $yymatches;
  91.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  92.                 if (!count($yymatches)) {
  93.                     throw new Exception('Error: lexing failed because a rule matched' .
  94.                         'an empty string.  Input "' substr($this->input,
  95.                         $this->N5'... state YYINITIAL');
  96.                 }
  97.                 next($yymatches)// skip global match
  98.                 $this->token key($yymatches)// token number
  99.                 if ($tokenMap[$this->token]{
  100.                     // extract sub-patterns for passing to lex function
  101.                     $yysubmatches array_slice($yysubmatches$this->token + 1,
  102.                         $tokenMap[$this->token]);
  103.                 else {
  104.                     $yysubmatches = array();
  105.                 }
  106.                 $this->value current($yymatches)// token value
  107.                 $r $this->{'yy_r1_' $this->token}($yysubmatches);
  108.                 if ($r === null{
  109.                     $this->+= strlen($this->value);
  110.                     $this->line += substr_count("\n"$this->value);
  111.                     // accept this token
  112.                     return true;
  113.                 elseif ($r === true{
  114.                     // we have changed state
  115.                     // process this token in the new state
  116.                     return $this->yylex();
  117.                 elseif ($r === false{
  118.                     $this->+= strlen($this->value);
  119.                     $this->line += substr_count("\n"$this->value);
  120.                     if ($this->>= strlen($this->input)) {
  121.                         return false; // end of input
  122.                     }
  123.                     // skip this token
  124.                     continue;
  125.                 else {                    $yy_yymore_patterns = array(
  126.         1 => "^(\\()|^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  127.         2 => "^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  128.         3 => "^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  129.         4 => "^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  130.         5 => "^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  131.         6 => "^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  132.         7 => "^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)",
  133.         8 => "^(O-O-O|O-O)|^([ \n\t]+)",
  134.         9 => "^([ \n\t]+)",
  135.         10 => "",
  136.     );
  137.  
  138.                     // yymore is needed
  139.                     do {
  140.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  141.                             throw new Exception('cannot do yymore for the last token');
  142.                         }
  143.                         if (preg_match($yy_yymore_patterns[$this->token],
  144.                               substr($this->input$this->N)$yymatches)) {
  145.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  146.                             next($yymatches)// skip global match
  147.                             $this->token key($yymatches)// token number
  148.                             $this->value current($yymatches)// token value
  149.                             $this->line substr_count("\n"$this->value);
  150.                         }
  151.                     while ($this->{'yy_r1_' $this->token}(!== null);
  152.                     // accept
  153.                     $this->+= strlen($this->value);
  154.                     $this->line += substr_count("\n"$this->value);
  155.                     return true;
  156.                 }
  157.             else {
  158.                 throw new Exception('Unexpected input at line' $this->line .
  159.                     ': ' $this->input[$this->N]);
  160.             }
  161.             break;
  162.         while (true);
  163.     // end function
  164.  
  165.  
  166.     const YYINITIAL = 1;
  167.     function yy_r1_1($yy_subpatterns)
  168.     {
  169.  
  170.     if ($this->debugecho 'new tag ['.$this->value."]\n";
  171.     $this->token = self::TAGOPEN;
  172.     $this->yybegin(self::INTAG);
  173.     }
  174.     function yy_r1_2($yy_subpatterns)
  175.     {
  176.  
  177.     $this->yybegin(self::INMOVES);
  178.     if ($this->debugecho '->found rav ['.$this->value."]\n";
  179.     $this->token = self::RAVOPEN;
  180.     }
  181.     function yy_r1_3($yy_subpatterns)
  182.     {
  183.  
  184.     // end of game
  185.     if ($this->debugecho 'found game end ['.$this->value."]\n";
  186.     $this->token = self::GAMEEND;
  187.     }
  188.     function yy_r1_4($yy_subpatterns)
  189.     {
  190.  
  191.     $this->yybegin(self::INMOVES);
  192.     if ($this->debugecho '->found digit ['.$this->value."]\n";
  193.     $this->token = self::DIGIT;
  194.     }
  195.     function yy_r1_5($yy_subpatterns)
  196.     {
  197.  
  198.     $this->yybegin(self::INMOVES);
  199.     if ($this->debugecho '->found pawn move ['.$this->value."]\n";
  200.     $this->token = self::PAWNMOVE;
  201.     }
  202.     function yy_r1_6($yy_subpatterns)
  203.     {
  204.  
  205.     $this->yybegin(self::INMOVES);
  206.     if ($this->debugecho '->found piece move ['.$this->value."]\n";
  207.     $this->token = self::PIECEMOVE;
  208.     }
  209.     function yy_r1_7($yy_subpatterns)
  210.     {
  211.  
  212.     $this->yybegin(self::INMOVES);
  213.     if ($this->debugecho '->found placement move ['.$this->value."]\n";
  214.     $this->token = self::PLACEMENTMOVE;
  215.     }
  216.     function yy_r1_8($yy_subpatterns)
  217.     {
  218.  
  219.     if ($this->debugecho 'new comment ['.$this->value."]\n";
  220.     $this->yypushstate(self::INCOMMENT);
  221.     $this->token = self::COMMENTOPEN;
  222.     }
  223.     function yy_r1_9($yy_subpatterns)
  224.     {
  225.  
  226.     $this->yybegin(self::INMOVES);
  227.     if ($this->debugecho 'found castle move ['.$this->value."]\n";
  228.     $this->token = self::CASTLE;
  229.     }
  230.     function yy_r1_10($yy_subpatterns)
  231.     {
  232.  
  233.     // cycle to next token
  234.     return false;
  235.     }
  236.  
  237.  
  238.     function yylex2()
  239.     {
  240.         $tokenMap = array (
  241.               1 => 0,
  242.               2 => 0,
  243.               3 => 0,
  244.               4 => 0,
  245.               5 => 0,
  246.               6 => 0,
  247.               7 => 0,
  248.               8 => 0,
  249.               9 => 0,
  250.               10 => 0,
  251.               11 => 0,
  252.               12 => 0,
  253.               13 => 0,
  254.               14 => 0,
  255.               15 => 0,
  256.               16 => 0,
  257.             );
  258.         if ($this->>= strlen($this->input)) {
  259.             return false; // end of input
  260.         }
  261.         $yy_global_pattern "/^(\\()|^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))/";
  262.  
  263.         do {
  264.             if (preg_match($yy_global_patternsubstr($this->input$this->N)$yymatches)) {
  265.                 $yysubmatches $yymatches;
  266.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  267.                 if (!count($yymatches)) {
  268.                     throw new Exception('Error: lexing failed because a rule matched' .
  269.                         'an empty string.  Input "' substr($this->input,
  270.                         $this->N5'... state INMOVES');
  271.                 }
  272.                 next($yymatches)// skip global match
  273.                 $this->token key($yymatches)// token number
  274.                 if ($tokenMap[$this->token]{
  275.                     // extract sub-patterns for passing to lex function
  276.                     $yysubmatches array_slice($yysubmatches$this->token + 1,
  277.                         $tokenMap[$this->token]);
  278.                 else {
  279.                     $yysubmatches = array();
  280.                 }
  281.                 $this->value current($yymatches)// token value
  282.                 $r $this->{'yy_r2_' $this->token}($yysubmatches);
  283.                 if ($r === null{
  284.                     $this->+= strlen($this->value);
  285.                     $this->line += substr_count("\n"$this->value);
  286.                     // accept this token
  287.                     return true;
  288.                 elseif ($r === true{
  289.                     // we have changed state
  290.                     // process this token in the new state
  291.                     return $this->yylex();
  292.                 elseif ($r === false{
  293.                     $this->+= strlen($this->value);
  294.                     $this->line += substr_count("\n"$this->value);
  295.                     if ($this->>= strlen($this->input)) {
  296.                         return false; // end of input
  297.                     }
  298.                     // skip this token
  299.                     continue;
  300.                 else {                    $yy_yymore_patterns = array(
  301.         1 => "^((?:1-0|0-1|1\2-1\2))|^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  302.         2 => "^([0-9]{1,3})|^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  303.         3 => "^(P?[a-h](?:[2-7]|[18]=(?:Q|R|B|N))|P?[a-h]x[a-h](?:[2-7]|[18]=(?:Q|R|B|N)))|^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  304.         4 => "^((?:Q|K|R|B|N)(?:[a-h]|[1-8])?[a-h][1-8]|(?:Q|K|R|B|N)(?:[a-h]|[1-8])?x[a-h][1-8])|^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  305.         5 => "^((?:P|K|Q|R|B|N)@[a-h][1-8])|^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  306.         6 => "^(\\{)|^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  307.         7 => "^(O-O-O|O-O)|^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  308.         8 => "^([ \n\t]+)|^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  309.         9 => "^(\\$[0-9]+)|^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  310.         10 => "^(\\*)|^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  311.         11 => "^(\\.)|^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  312.         12 => "^(\\+)|^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  313.         13 => "^(#)|^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  314.         14 => "^(!|\\?|!!|\\?\\?|!\\?|\\?!)|^(\\))",
  315.         15 => "^(\\))",
  316.         16 => "",
  317.     );
  318.  
  319.                     // yymore is needed
  320.                     do {
  321.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  322.                             throw new Exception('cannot do yymore for the last token');
  323.                         }
  324.                         if (preg_match($yy_yymore_patterns[$this->token],
  325.                               substr($this->input$this->N)$yymatches)) {
  326.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  327.                             next($yymatches)// skip global match
  328.                             $this->token key($yymatches)// token number
  329.                             $this->value current($yymatches)// token value
  330.                             $this->line substr_count("\n"$this->value);
  331.                         }
  332.                     while ($this->{'yy_r2_' $this->token}(!== null);
  333.                     // accept
  334.                     $this->+= strlen($this->value);
  335.                     $this->line += substr_count("\n"$this->value);
  336.                     return true;
  337.                 }
  338.             else {
  339.                 throw new Exception('Unexpected input at line' $this->line .
  340.                     ': ' $this->input[$this->N]);
  341.             }
  342.             break;
  343.         while (true);
  344.     // end function
  345.  
  346.  
  347.     const INMOVES = 2;
  348.     function yy_r2_1($yy_subpatterns)
  349.     {
  350.  
  351.     if ($this->debugecho '->found rav ['.$this->value."]\n";
  352.     $this->token = self::RAVOPEN;
  353.     }
  354.     function yy_r2_2($yy_subpatterns)
  355.     {
  356.  
  357.     // end of game
  358.     $this->yybegin(self::YYINITIAL);
  359.     if ($this->debugecho 'found game end ['.$this->value."]\n";
  360.     $this->token = self::GAMEEND;
  361.     }
  362.     function yy_r2_3($yy_subpatterns)
  363.     {
  364.  
  365.     if ($this->debugecho '->found digit ['.$this->value."]\n";
  366.     $this->token = self::DIGIT;
  367.     }
  368.     function yy_r2_4($yy_subpatterns)
  369.     {
  370.  
  371.     if ($this->debugecho '->found pawn move ['.$this->value."]\n";
  372.     $this->token = self::PAWNMOVE;
  373.     }
  374.     function yy_r2_5($yy_subpatterns)
  375.     {
  376.  
  377.     if ($this->debugecho '->found piece move ['.$this->value."]\n";
  378.     $this->token = self::PIECEMOVE;
  379.     }
  380.     function yy_r2_6($yy_subpatterns)
  381.     {
  382.  
  383.     if ($this->debugecho '->found placement move ['.$this->value."]\n";
  384.     $this->token = self::PLACEMENTMOVE;
  385.     }
  386.     function yy_r2_7($yy_subpatterns)
  387.     {
  388.  
  389.     if ($this->debugecho 'new comment ['.$this->value."]\n";
  390.     $this->yypushstate(self::INCOMMENT);
  391.     $this->token = self::COMMENTOPEN;
  392.     }
  393.     function yy_r2_8($yy_subpatterns)
  394.     {
  395.  
  396.     if ($this->debugecho 'found castle move ['.$this->value."]\n";
  397.     $this->token = self::CASTLE;
  398.     }
  399.     function yy_r2_9($yy_subpatterns)
  400.     {
  401.  
  402.     // cycle to next token
  403.     return false;
  404.     }
  405.     function yy_r2_10($yy_subpatterns)
  406.     {
  407.  
  408.     if ($this->debugecho 'found numeric annotation glyph ['.$this->value."]\n";
  409.     $this->token = self::NAG;
  410.     }
  411.     function yy_r2_11($yy_subpatterns)
  412.     {
  413.  
  414.     // end of game
  415.     $this->yybegin(self::YYINITIAL);
  416.     if ($this->debugecho 'found unfinished game indicator ['.$this->value."]\n";
  417.     $this->token = self::GAMEEND;
  418.     }
  419.     function yy_r2_12($yy_subpatterns)
  420.     {
  421.  
  422.     if ($this->debugecho 'found period ['.$this->value."]\n";
  423.     $this->token = self::PERIOD;
  424.     }
  425.     function yy_r2_13($yy_subpatterns)
  426.     {
  427.  
  428.     if ($this->debugecho 'found check ['.$this->value."]\n";
  429.     $this->token = self::CHECK;
  430.     }
  431.     function yy_r2_14($yy_subpatterns)
  432.     {
  433.  
  434.     if ($this->debugecho 'found mate ['.$this->value."]\n";
  435.     $this->token = self::MATE;
  436.     }
  437.     function yy_r2_15($yy_subpatterns)
  438.     {
  439.  
  440.     if ($this->debugecho 'found move annotation ['.$this->value."]\n";
  441.     $this->token = self::MOVEANNOT;
  442.     }
  443.     function yy_r2_16($yy_subpatterns)
  444.     {
  445.  
  446.     if ($this->debugecho 'found recursive annotation variation close ['.$this->value."]\n";
  447.     $this->token = self::RAVCLOSE;
  448.     }
  449.  
  450.  
  451.     function yylex3()
  452.     {
  453.         $tokenMap = array (
  454.               1 => 0,
  455.               2 => 0,
  456.               3 => 0,
  457.               4 => 0,
  458.             );
  459.         if ($this->>= strlen($this->input)) {
  460.             return false; // end of input
  461.         }
  462.         $yy_global_pattern "/^(\")|^(\\])|^([^\\]\" ]+)|^( )/";
  463.  
  464.         do {
  465.             if (preg_match($yy_global_patternsubstr($this->input$this->N)$yymatches)) {
  466.                 $yysubmatches $yymatches;
  467.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  468.                 if (!count($yymatches)) {
  469.                     throw new Exception('Error: lexing failed because a rule matched' .
  470.                         'an empty string.  Input "' substr($this->input,
  471.                         $this->N5'... state INTAG');
  472.                 }
  473.                 next($yymatches)// skip global match
  474.                 $this->token key($yymatches)// token number
  475.                 if ($tokenMap[$this->token]{
  476.                     // extract sub-patterns for passing to lex function
  477.                     $yysubmatches array_slice($yysubmatches$this->token + 1,
  478.                         $tokenMap[$this->token]);
  479.                 else {
  480.                     $yysubmatches = array();
  481.                 }
  482.                 $this->value current($yymatches)// token value
  483.                 $r $this->{'yy_r3_' $this->token}($yysubmatches);
  484.                 if ($r === null{
  485.                     $this->+= strlen($this->value);
  486.                     $this->line += substr_count("\n"$this->value);
  487.                     // accept this token
  488.                     return true;
  489.                 elseif ($r === true{
  490.                     // we have changed state
  491.                     // process this token in the new state
  492.                     return $this->yylex();
  493.                 elseif ($r === false{
  494.                     $this->+= strlen($this->value);
  495.                     $this->line += substr_count("\n"$this->value);
  496.                     if ($this->>= strlen($this->input)) {
  497.                         return false; // end of input
  498.                     }
  499.                     // skip this token
  500.                     continue;
  501.                 else {                    $yy_yymore_patterns = array(
  502.         1 => "^(\\])|^([^\\]\" ]+)|^( )",
  503.         2 => "^([^\\]\" ]+)|^( )",
  504.         3 => "^( )",
  505.         4 => "",
  506.     );
  507.  
  508.                     // yymore is needed
  509.                     do {
  510.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  511.                             throw new Exception('cannot do yymore for the last token');
  512.                         }
  513.                         if (preg_match($yy_yymore_patterns[$this->token],
  514.                               substr($this->input$this->N)$yymatches)) {
  515.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  516.                             next($yymatches)// skip global match
  517.                             $this->token key($yymatches)// token number
  518.                             $this->value current($yymatches)// token value
  519.                             $this->line substr_count("\n"$this->value);
  520.                         }
  521.                     while ($this->{'yy_r3_' $this->token}(!== null);
  522.                     // accept
  523.                     $this->+= strlen($this->value);
  524.                     $this->line += substr_count("\n"$this->value);
  525.                     return true;
  526.                 }
  527.             else {
  528.                 throw new Exception('Unexpected input at line' $this->line .
  529.                     ': ' $this->input[$this->N]);
  530.             }
  531.             break;
  532.         while (true);
  533.     // end function
  534.  
  535.  
  536.     const INTAG = 3;
  537.     function yy_r3_1($yy_subpatterns)
  538.     {
  539.  
  540.     if ($this->debugecho "starting string\n";
  541.     $this->yybegin(self::INSTRING);
  542.     $this->_string '';
  543.     $this->N++;
  544.     return true; // cycle to next state
  545.     }
  546.     function yy_r3_2($yy_subpatterns)
  547.     {
  548.  
  549.     if ($this->debugecho "ending tag [".$this->value."]\n";
  550.     $this->yybegin(self::YYINITIAL);
  551.     $this->token = self::TAGCLOSE;
  552.     }
  553.     function yy_r3_3($yy_subpatterns)
  554.     {
  555.  
  556.     if ($this->debugecho 'tag contents ['.$this->value."]\n";
  557.     $this->token = self::TAGNAME;
  558.     }
  559.     function yy_r3_4($yy_subpatterns)
  560.     {
  561.  
  562.     // skip token
  563.     return false;
  564.     }
  565.  
  566.  
  567.     function yylex4()
  568.     {
  569.         $tokenMap = array (
  570.               1 => 0,
  571.               2 => 0,
  572.               3 => 0,
  573.             );
  574.         if ($this->>= strlen($this->input)) {
  575.             return false; // end of input
  576.         }
  577.         $yy_global_pattern "/^(\\\\)|^(\")|^([^[\"\\\\]+)/";
  578.  
  579.         do {
  580.             if (preg_match($yy_global_patternsubstr($this->input$this->N)$yymatches)) {
  581.                 $yysubmatches $yymatches;
  582.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  583.                 if (!count($yymatches)) {
  584.                     throw new Exception('Error: lexing failed because a rule matched' .
  585.                         'an empty string.  Input "' substr($this->input,
  586.                         $this->N5'... state INSTRING');
  587.                 }
  588.                 next($yymatches)// skip global match
  589.                 $this->token key($yymatches)// token number
  590.                 if ($tokenMap[$this->token]{
  591.                     // extract sub-patterns for passing to lex function
  592.                     $yysubmatches array_slice($yysubmatches$this->token + 1,
  593.                         $tokenMap[$this->token]);
  594.                 else {
  595.                     $yysubmatches = array();
  596.                 }
  597.                 $this->value current($yymatches)// token value
  598.                 $r $this->{'yy_r4_' $this->token}($yysubmatches);
  599.                 if ($r === null{
  600.                     $this->+= strlen($this->value);
  601.                     $this->line += substr_count("\n"$this->value);
  602.                     // accept this token
  603.                     return true;
  604.                 elseif ($r === true{
  605.                     // we have changed state
  606.                     // process this token in the new state
  607.                     return $this->yylex();
  608.                 elseif ($r === false{
  609.                     $this->+= strlen($this->value);
  610.                     $this->line += substr_count("\n"$this->value);
  611.                     if ($this->>= strlen($this->input)) {
  612.                         return false; // end of input
  613.                     }
  614.                     // skip this token
  615.                     continue;
  616.                 else {                    $yy_yymore_patterns = array(
  617.         1 => "^(\")|^([^[\"\\\\]+)",
  618.         2 => "^([^[\"\\\\]+)",
  619.         3 => "",
  620.     );
  621.  
  622.                     // yymore is needed
  623.                     do {
  624.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  625.                             throw new Exception('cannot do yymore for the last token');
  626.                         }
  627.                         if (preg_match($yy_yymore_patterns[$this->token],
  628.                               substr($this->input$this->N)$yymatches)) {
  629.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  630.                             next($yymatches)// skip global match
  631.                             $this->token key($yymatches)// token number
  632.                             $this->value current($yymatches)// token value
  633.                             $this->line substr_count("\n"$this->value);
  634.                         }
  635.                     while ($this->{'yy_r4_' $this->token}(!== null);
  636.                     // accept
  637.                     $this->+= strlen($this->value);
  638.                     $this->line += substr_count("\n"$this->value);
  639.                     return true;
  640.                 }
  641.             else {
  642.                 throw new Exception('Unexpected input at line' $this->line .
  643.                     ': ' $this->input[$this->N]);
  644.             }
  645.             break;
  646.         while (true);
  647.     // end function
  648.  
  649.  
  650.     const INSTRING = 4;
  651.     function yy_r4_1($yy_subpatterns)
  652.     {
  653.  
  654.     if ($this->debugecho "string escape [\\]\n";
  655.     $this->yybegin(self::INESCAPE);
  656.     return true;
  657.     }
  658.     function yy_r4_2($yy_subpatterns)
  659.     {
  660.  
  661.     if ($this->debugecho "returning string [$this->_string]\n";
  662.     $this->yybegin(self::INTAG);
  663.     $this->value $this->_string;
  664.     $this->token = self::STRING;
  665.     $this->-= strlen($this->_string- 1; // make sure the counter is right
  666.     $this->_string '';
  667.     }
  668.     function yy_r4_3($yy_subpatterns)
  669.     {
  670.  
  671.     if ($this->debugecho "added to string [".$this->value."]\n";
  672.     $this->_string .= $this->value;
  673.     return false;
  674.     }
  675.  
  676.  
  677.     function yylex5()
  678.     {
  679.         $tokenMap = array (
  680.               1 => 0,
  681.               2 => 0,
  682.             );
  683.         if ($this->>= strlen($this->input)) {
  684.             return false; // end of input
  685.         }
  686.         $yy_global_pattern "/^(\"|\\\\)|^(.)/";
  687.  
  688.         do {
  689.             if (preg_match($yy_global_patternsubstr($this->input$this->N)$yymatches)) {
  690.                 $yysubmatches $yymatches;
  691.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  692.                 if (!count($yymatches)) {
  693.                     throw new Exception('Error: lexing failed because a rule matched' .
  694.                         'an empty string.  Input "' substr($this->input,
  695.                         $this->N5'... state INESCAPE');
  696.                 }
  697.                 next($yymatches)// skip global match
  698.                 $this->token key($yymatches)// token number
  699.                 if ($tokenMap[$this->token]{
  700.                     // extract sub-patterns for passing to lex function
  701.                     $yysubmatches array_slice($yysubmatches$this->token + 1,
  702.                         $tokenMap[$this->token]);
  703.                 else {
  704.                     $yysubmatches = array();
  705.                 }
  706.                 $this->value current($yymatches)// token value
  707.                 $r $this->{'yy_r5_' $this->token}($yysubmatches);
  708.                 if ($r === null{
  709.                     $this->+= strlen($this->value);
  710.                     $this->line += substr_count("\n"$this->value);
  711.                     // accept this token
  712.                     return true;
  713.                 elseif ($r === true{
  714.                     // we have changed state
  715.                     // process this token in the new state
  716.                     return $this->yylex();
  717.                 elseif ($r === false{
  718.                     $this->+= strlen($this->value);
  719.                     $this->line += substr_count("\n"$this->value);
  720.                     if ($this->>= strlen($this->input)) {
  721.                         return false; // end of input
  722.                     }
  723.                     // skip this token
  724.                     continue;
  725.                 else {                    $yy_yymore_patterns = array(
  726.         1 => "^(.)",
  727.         2 => "",
  728.     );
  729.  
  730.                     // yymore is needed
  731.                     do {
  732.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  733.                             throw new Exception('cannot do yymore for the last token');
  734.                         }
  735.                         if (preg_match($yy_yymore_patterns[$this->token],
  736.                               substr($this->input$this->N)$yymatches)) {
  737.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  738.                             next($yymatches)// skip global match
  739.                             $this->token key($yymatches)// token number
  740.                             $this->value current($yymatches)// token value
  741.                             $this->line substr_count("\n"$this->value);
  742.                         }
  743.                     while ($this->{'yy_r5_' $this->token}(!== null);
  744.                     // accept
  745.                     $this->+= strlen($this->value);
  746.                     $this->line += substr_count("\n"$this->value);
  747.                     return true;
  748.                 }
  749.             else {
  750.                 throw new Exception('Unexpected input at line' $this->line .
  751.                     ': ' $this->input[$this->N]);
  752.             }
  753.             break;
  754.         while (true);
  755.     // end function
  756.  
  757.  
  758.     const INESCAPE = 5;
  759.     function yy_r5_1($yy_subpatterns)
  760.     {
  761.  
  762.     if ($this->debugecho "escape [".$this->value."]\n";
  763.     $this->yybegin(self::INSTRING);
  764.     $this->_string .= $this->value;
  765.     break;
  766.     }
  767.     function yy_r5_2($yy_subpatterns)
  768.     {
  769.  
  770.     if ($this->debugecho "non-escape [".$this->value."]\n";
  771.     $this->yybegin(self::INSTRING);
  772.     $this->_string .= $this->value;
  773.     return false;
  774.     }
  775.  
  776.  
  777.     function yylex6()
  778.     {
  779.         $tokenMap = array (
  780.               1 => 0,
  781.               2 => 0,
  782.             );
  783.         if ($this->>= strlen($this->input)) {
  784.             return false; // end of input
  785.         }
  786.         $yy_global_pattern "/^(\\})|^([^}]+)/";
  787.  
  788.         do {
  789.             if (preg_match($yy_global_patternsubstr($this->input$this->N)$yymatches)) {
  790.                 $yysubmatches $yymatches;
  791.                 $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  792.                 if (!count($yymatches)) {
  793.                     throw new Exception('Error: lexing failed because a rule matched' .
  794.                         'an empty string.  Input "' substr($this->input,
  795.                         $this->N5'... state INCOMMENT');
  796.                 }
  797.                 next($yymatches)// skip global match
  798.                 $this->token key($yymatches)// token number
  799.                 if ($tokenMap[$this->token]{
  800.                     // extract sub-patterns for passing to lex function
  801.                     $yysubmatches array_slice($yysubmatches$this->token + 1,
  802.                         $tokenMap[$this->token]);
  803.                 else {
  804.                     $yysubmatches = array();
  805.                 }
  806.                 $this->value current($yymatches)// token value
  807.                 $r $this->{'yy_r6_' $this->token}($yysubmatches);
  808.                 if ($r === null{
  809.                     $this->+= strlen($this->value);
  810.                     $this->line += substr_count("\n"$this->value);
  811.                     // accept this token
  812.                     return true;
  813.                 elseif ($r === true{
  814.                     // we have changed state
  815.                     // process this token in the new state
  816.                     return $this->yylex();
  817.                 elseif ($r === false{
  818.                     $this->+= strlen($this->value);
  819.                     $this->line += substr_count("\n"$this->value);
  820.                     if ($this->>= strlen($this->input)) {
  821.                         return false; // end of input
  822.                     }
  823.                     // skip this token
  824.                     continue;
  825.                 else {                    $yy_yymore_patterns = array(
  826.         1 => "^([^}]+)",
  827.         2 => "",
  828.     );
  829.  
  830.                     // yymore is needed
  831.                     do {
  832.                         if (!strlen($yy_yymore_patterns[$this->token])) {
  833.                             throw new Exception('cannot do yymore for the last token');
  834.                         }
  835.                         if (preg_match($yy_yymore_patterns[$this->token],
  836.                               substr($this->input$this->N)$yymatches)) {
  837.                             $yymatches array_filter($yymatches'strlen')// remove empty sub-patterns
  838.                             next($yymatches)// skip global match
  839.                             $this->token key($yymatches)// token number
  840.                             $this->value current($yymatches)// token value
  841.                             $this->line substr_count("\n"$this->value);
  842.                         }
  843.                     while ($this->{'yy_r6_' $this->token}(!== null);
  844.                     // accept
  845.                     $this->+= strlen($this->value);
  846.                     $this->line += substr_count("\n"$this->value);
  847.                     return true;
  848.                 }
  849.             else {
  850.                 throw new Exception('Unexpected input at line' $this->line .
  851.                     ': ' $this->input[$this->N]);
  852.             }
  853.             break;
  854.         while (true);
  855.     // end function
  856.  
  857.  
  858.     const INCOMMENT = 6;
  859.     function yy_r6_1($yy_subpatterns)
  860.     {
  861.  
  862.     if ($this->debugecho 'close comment ['.$this->value."]\n";
  863.     $this->yypopstate();
  864.     $this->token = self::COMMENTCLOSE;
  865.     }
  866.     function yy_r6_2($yy_subpatterns)
  867.     {
  868.  
  869.     if ($this->debugecho 'comment contents ['.$this->value."]\n";
  870.     $this->token = self::COMMENT;
  871.     }
  872.  
  873.     /**
  874.      * return something useful, when a parse error occurs.
  875.      *
  876.      * used to build error messages if the parser fails, and needs to know the line number..
  877.      *
  878.      * @return   string 
  879.      * @access   public
  880.      */
  881.     function parseError(
  882.     {
  883.         return "Error at line {$this->yyline}";
  884.         
  885.     }

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