3v4l.org

run code in 300+ PHP versions simultaneously
<?php class interpreter { private $_code; public function __construct($code) { if(!is_string($code)) exit('Error while parsing code; Code not conformal.'); $this->_code = $code; $this->parser(); } public function parser($code = null) { if($code === null) $code = $this->_code; $calls = []; $variables = []; preg_match('#(.*)\((.*)\)#', $code, $calls); if($calls && isset($calls[0])) $this->calls($calls); } private function calls(array $calls) { switch($calls[1]) { case 'print': $this->func_print($calls[2]); break; } } private function func_print($arg) { if(preg_match('#^("|\')(.*)("|\')$#', $arg)) $arg = preg_replace('#^("|\')(.*)("|\')$#', '$2', $arg); echo($arg); } } $code = <<<CODE int var = 1; if(var == 1) { console.out.println("Hello World!"); } else { console.out.println("Hi!"); } CODE; $program = new interpreter($code);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1B13W
function name:  (null)
number of ops:  6
compiled vars:  !0 = $code, !1 = $program
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, 'int+var+%3D+1%3B%0Aif%28var+%3D%3D+1%29+%7B%0A++++console.out.println%28%22Hello+World%21%22%29%3B%0A%7D%0Aelse+%7B%0A++++console.out.println%28%22Hi%21%22%29%3B%0A%7D'
   35     1        NEW                                              $3      'interpreter'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
          5      > RETURN                                                   1

Class interpreter:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1B13W
function name:  __construct
number of ops:  10
compiled vars:  !0 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        TYPE_CHECK                                   64  ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->5
          4    > > EXIT                                                     'Error+while+parsing+code%3B+Code+not+conformal.'
    6     5    >   ASSIGN_OBJ                                               '_code'
          6        OP_DATA                                                  !0
    7     7        INIT_METHOD_CALL                                         'parser'
          8        DO_FCALL                                      0          
    8     9      > RETURN                                                   null

End of function __construct

Function parser:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 15
Branch analysis from position: 5
filename:       /in/1B13W
function name:  parser
number of ops:  20
compiled vars:  !0 = $code, !1 = $calls, !2 = $variables
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      null
   10     1        TYPE_CHECK                                    2          !0
          2      > JMPZ                                                     ~3, ->5
          3    >   FETCH_OBJ_R                                      ~4      '_code'
          4        ASSIGN                                                   !0, ~4
   11     5    >   ASSIGN                                                   !1, <array>
   12     6        ASSIGN                                                   !2, <array>
   13     7        INIT_FCALL                                               'preg_match'
          8        SEND_VAL                                                 '%23%28.%2A%29%5C%28%28.%2A%29%5C%29%23'
          9        SEND_VAR                                                 !0
         10        SEND_REF                                                 !1
         11        DO_ICALL                                                 
   14    12      > JMPZ_EX                                          ~9      !1, ->15
         13    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !1, 0
         14        BOOL                                             ~9      ~10
         15    > > JMPZ                                                     ~9, ->19
         16    >   INIT_METHOD_CALL                                         'calls'
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0          
   15    19    > > RETURN                                                   null

End of function parser

Function calls:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
filename:       /in/1B13W
function name:  calls
number of ops:  13
compiled vars:  !0 = $calls
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        FETCH_DIM_R                                      ~1      !0, 1
   18     2        CASE                                                     ~1, 'print'
          3      > JMPNZ                                                    ~2, ->5
          4    > > JMP                                                      ->11
          5    >   INIT_METHOD_CALL                                         'func_print'
          6        CHECK_FUNC_ARG                                           
          7        FETCH_DIM_FUNC_ARG                               $3      !0, 2
          8        SEND_FUNC_ARG                                            $3
          9        DO_FCALL                                      0          
         10      > JMP                                                      ->11
         11    >   FREE                                                     ~1
   20    12      > RETURN                                                   null

End of function calls

Function func_print:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/1B13W
function name:  func_print
number of ops:  14
compiled vars:  !0 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%23%5E%28%22%7C%27%29%28.%2A%29%28%22%7C%27%29%24%23'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->12
          6    >   INIT_FCALL                                               'preg_replace'
          7        SEND_VAL                                                 '%23%5E%28%22%7C%27%29%28.%2A%29%28%22%7C%27%29%24%23'
          8        SEND_VAL                                                 '%242'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $2      
         11        ASSIGN                                                   !0, $2
   23    12    >   ECHO                                                     !0
   24    13      > RETURN                                                   null

End of function func_print

End of class interpreter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
200.84 ms | 1408 KiB | 17 Q