3v4l.org

run code in 300+ PHP versions simultaneously
<?php class tokenstream { // Входной поток private $input_stream; // Указатель позиции во входном потоке public $seek = 0; // Конструктор public function __construct ( $input ) { // Инициализируем входной поток $this -> input_stream = $input; } // Возвращает очередной символ из входного потока public function readChar ( ) { $char = ( isset ( $this -> input_stream [ $this -> seek ] ) ? $this -> input_stream [ $this -> seek ] : false ); $this -> seek++; return $char; } // Производит токенизацию public function tokenize ( ) { $output = array ( ); while ( ( $char = $this -> readChar ( ) ) !== false ) { if ( preg_match ( '/\s/', $char ) ) { // Неотображаемые символы } elseif ( preg_match ( '/\"/', $char ) ) { // Кавычки $output [ ] = 'T_QUOTE'; } elseif ( условие ) { $output [ ] = 'T_...'; } } return $output; } } // Исходный код для разбора $my_source = ' function foo ( ) { $my_var = "foo-bar"; } '; // Создаем экземпляр класса парсера $tokenstream = new tokenstream ( $my_source ); // Парсим исходный код и распечатываем результат print_r ( $tokenstream -> tokenize ( ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z7n9p
function name:  (null)
number of ops:  11
compiled vars:  !0 = $my_source, !1 = $tokenstream
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, '%0A++function+foo+%28+%29+%7B%0A+++%24my_var+%3D+%22foo-bar%22%3B%0A++%7D++%0A+'
   39     1        NEW                                              $3      'tokenstream'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   41     5        INIT_FCALL                                               'print_r'
          6        INIT_METHOD_CALL                                         !1, 'tokenize'
          7        DO_FCALL                                      0  $6      
          8        SEND_VAR                                                 $6
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Class tokenstream:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z7n9p
function name:  __construct
number of ops:  4
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        ASSIGN_OBJ                                               'input_stream'
          2        OP_DATA                                                  !0
   11     3      > RETURN                                                   null

End of function __construct

Function readchar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z7n9p
function name:  readChar
number of ops:  14
compiled vars:  !0 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~2      'seek'
          1        FETCH_OBJ_IS                                     ~1      'input_stream'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, ~2
          3      > JMPZ                                                     ~3, ->9
          4    >   FETCH_OBJ_R                                      ~5      'seek'
          5        FETCH_OBJ_R                                      ~4      'input_stream'
          6        FETCH_DIM_R                                      ~6      ~4, ~5
          7        QM_ASSIGN                                        ~7      ~6
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~7      <false>
         10    >   ASSIGN                                                   !0, ~7
   15    11        PRE_INC_OBJ                                              'seek'
   16    12      > RETURN                                                   !0
   17    13*     > RETURN                                                   null

End of function readchar

Function tokenize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 2
Branch analysis from position: 25
Branch analysis from position: 2
Branch analysis from position: 20
filename:       /in/Z7n9p
function name:  tokenize
number of ops:  27
compiled vars:  !0 = $output, !1 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, <array>
   21     1      > JMP                                                      ->20
   22     2    >   INIT_FCALL                                               'preg_match'
          3        SEND_VAL                                                 '%2F%5Cs%2F'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6      > JMPZ                                                     $3, ->8
          7    > > JMP                                                      ->20
   23     8    >   INIT_FCALL                                               'preg_match'
          9        SEND_VAL                                                 '%2F%5C%22%2F'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $4      
         12      > JMPZ                                                     $4, ->16
   24    13    >   ASSIGN_DIM                                               !0
         14        OP_DATA                                                  'T_QUOTE'
         15      > JMP                                                      ->20
   25    16    >   FETCH_CONSTANT                                   ~6      '%D1%83%D1%81%D0%BB%D0%BE%D0%B2%D0%B8%D0%B5'
         17      > JMPZ                                                     ~6, ->20
   26    18    >   ASSIGN_DIM                                               !0
         19        OP_DATA                                                  'T_...'
   21    20    >   INIT_METHOD_CALL                                         'readChar'
         21        DO_FCALL                                      0  $8      
         22        ASSIGN                                           ~9      !1, $8
         23        TYPE_CHECK                                  1018          ~9
         24      > JMPNZ                                                    ~10, ->2
   29    25    > > RETURN                                                   !0
   30    26*     > RETURN                                                   null

End of function tokenize

End of class tokenstream.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.95 ms | 1400 KiB | 17 Q