lexer.php

来自「太烦了」· PHP 代码 · 共 568 行 · 第 1/2 页

PHP
568
字号
                }                if ($this->isCompop($c)) { // comparison operator                    $state = 10;                    break;                }                // Unknown token.  Revert to single char                $state = 999;                break;            // }}}            // {{{ State 1 : Incomplete keyword or ident            case 1:                $c = $this->get();                if (ctype_alnum(ord($c)) || ($c == '_') || ($c == '.')) {                    $state = 1;                    break;                }                $state = 2;                break;            // }}}            /* {{{ State 2 : Complete keyword or ident */            case 2:                $this->unget();                $this->tokText = substr($this->string, $this->tokStart,                                        $this->tokLen);                                $testToken = strtolower($this->tokText);                if (isset($this->symbols[$testToken])) {                                    $this->skipText = substr($this->string, $this->tokAbsStart,                                            $this->tokStart-$this->tokAbsStart);                    $this->tokStart = $this->tokPtr;                    return $testToken;                } else {                    $this->skipText = substr($this->string, $this->tokAbsStart,                                            $this->tokStart-$this->tokAbsStart);                    $this->tokStart = $this->tokPtr;                    return 'ident';                }                break;            // }}}            // {{{ State 5: Incomplete real or int number            case 5:                $c = $this->get();                if (ctype_digit(ord($c))) {                    $state = 5;                    break;                } else if ($c == '.') {                    $t = $this->get();                    if($t == '.') { // ellipsis                        $this->unget();                    } else { // real number                        $state = 7;                        break;                    }                } else if(ctype_alpha(ord($c))) { // number must end with non-alpha character                    $state = 999;                    break;                } else {                // complete number                $state = 6;                break;                }            // }}}            // {{{ State 6: Complete integer number            case 6:                $this->unget();                $this->tokText = intval(substr($this->string, $this->tokStart,                                               $this->tokLen));                $this->skipText = substr($this->string, $this->tokAbsStart,                                         $this->tokStart-$this->tokAbsStart);                $this->tokStart = $this->tokPtr;                return 'int_val';                break;            // }}}            // {{{ State 7: Incomplete real number            case 7:                $c = $this->get();                /* Analogy Start */                if ($c == 'e' || $c == 'E') {                        $state = 15;                        break;                }                /* Analogy End   */                if (ctype_digit(ord($c))) {                    $state = 7;                    break;                }                $state = 8;                break;            // }}}            // {{{ State 8: Complete real number */            case 8:                $this->unget();                $this->tokText = floatval(substr($this->string, $this->tokStart,                                        $this->tokLen));                $this->skipText = substr($this->string, $this->tokAbsStart,                                         $this->tokStart-$this->tokAbsStart);                $this->tokStart = $this->tokPtr;                return 'real_val';            // }}}            // {{{ State 10: Incomplete comparison operator            case 10:                $c = $this->get();                if ($this->isCompop($c))                {                    $state = 10;                    break;                }                $state = 11;                break;            // }}}            // {{{ State 11: Complete comparison operator            case 11:                $this->unget();                $this->tokText = substr($this->string, $this->tokStart,                                        $this->tokLen);                if($this->tokText) {                    $this->skipText = substr($this->string, $this->tokAbsStart,                                            $this->tokStart-$this->tokAbsStart);                    $this->tokStart = $this->tokPtr;                    return $this->tokText;                }                $state = 999;                break;            // }}}            // {{{ State 12: Incomplete text string            case 12:                $bail = false;                while (!$bail) {                    switch ($this->get()) {                        case '':                            $this->tokText = null;                            $bail = true;                            break;                        case "\\":                            if ( $this->get() === null ) {                                $this->tokText = null;                                $bail = true;                            }                                //$bail = true;                            break;                        case $quote:                            $this->tokText = stripslashes(substr($this->string,                                       ($this->tokStart+1), ($this->tokLen-2)));                            $bail = true;                            break;                    }                }                if (!is_null($this->tokText)) {                    $state = 13;                    break;                }                $state = 999;                break;            // }}}            // {{{ State 13: Complete text string            case 13:                $this->skipText = substr($this->string, $this->tokAbsStart,                                         $this->tokStart-$this->tokAbsStart);                $this->tokStart = $this->tokPtr;                return 'text_val';                break;            // }}}            // {{{ State 14: Comment            case 14:                $c = $this->skip();                if ($c == "\n" || $c == "\r" || $c == "") {                    // Handle MAC/Unix/Windows line endings.                    if ($c == "\r") {                        $c = $this->skip();                        // If not DOS newline                        if ($c != "\n") {                            $this->unget();                        }                    }                    if ($c != "") {                        ++$this->lineNo;                        $this->lineBegin = $this->tokPtr;                    }                    // We need to skip all the text.                    $this->tokStart = $this->tokPtr;                    $state = 0;                } else {                    $state = 14;                }                break;            // }}}            // {{{ State 15: Exponent Sign in Scientific Notation            case 15:                    $c = $this->get();                    if($c == '-' || $c == '+') {                            $state = 16;                            break;                    }                    $state = 999;                    break;            // }}}            // {{{ state 16: Exponent Value-first digit in Scientific Notation            case 16:                    $c = $this->get();                    if (ctype_digit(ord($c))) {                            $state = 17;                            break;                    }                    $state = 999;  // if no digit, then token is unknown                    break;            // }}}            // {{{ State 17: Exponent Value in Scientific Notation            case 17:                    $c = $this->get();                    if (ctype_digit(ord($c))) {                            $state = 17;                            break;                    }                    $state = 8;  // At least 1 exponent digit was required                    break;            // }}}            // {{{ State 18 : Incomplete System Variable            case 18:                $c = $this->get();                if (ctype_alnum(ord($c)) || $c == '_') {                    $state = 18;                    break;                }                $state = 19;                break;            // }}}            // {{{ State 19: Complete Sys Var            case 19:                $this->unget();                $this->tokText = substr($this->string, $this->tokStart,                                        $this->tokLen);                $this->skipText = substr($this->string, $this->tokAbsStart,                                         $this->tokStart-$this->tokAbsStart);                $this->tokStart = $this->tokPtr;                return 'sys_var';            // }}}            // {{{ State 999 : Unknown token.  Revert to single char            case 999:                $this->revert();                $this->tokText = $this->get();                $this->skipText = substr($this->string, $this->tokAbsStart,                                         $this->tokStart-$this->tokAbsStart);                $this->tokStart = $this->tokPtr;                return $this->tokText;            // }}}            // {{{ State 1000 : End Of Input            case 1000:                $this->tokText = '*end of input*';                $this->skipText = substr($this->string, $this->tokAbsStart,                                         $this->tokStart-$this->tokAbsStart);                $this->tokStart = $this->tokPtr;                return null;            // }}}        }    }}// }}}}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?