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 = []; $conditions = []; preg_match('#(.*)\((.*)\)#', $code, $calls); preg_match('#if\((.*)\) \{(.*)\}#s', $code, $conditions); if($conditions && isset($conditions[0])) $this->conditions_ifelse($conditions); 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 condition_ifelse(array $conditions) { if(!preg_match('#(.*)(==|===|\<|\<=|\>|\>=|!=|!==|&&|\|\||AND|OR|XOR)(.*)#i', $conditions[1])) exit('Condition parsing error.'); } } abstract class lang { const version = 0.1; } class console extends lang { } class out extends console { public function println($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/uth5B
function name:  (null)
number of ops:  6
compiled vars:  !0 = $code, !1 = $program
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     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'
   49     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/uth5B
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 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 28
Branch analysis from position: 25
Branch analysis from position: 21
Branch analysis from position: 5
filename:       /in/uth5B
function name:  parser
number of ops:  33
compiled vars:  !0 = $code, !1 = $calls, !2 = $variables, !3 = $conditions
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      null
   10     1        TYPE_CHECK                                    2          !0
          2      > JMPZ                                                     ~4, ->5
          3    >   FETCH_OBJ_R                                      ~5      '_code'
          4        ASSIGN                                                   !0, ~5
   11     5    >   ASSIGN                                                   !1, <array>
   12     6        ASSIGN                                                   !2, <array>
   13     7        ASSIGN                                                   !3, <array>
   14     8        INIT_FCALL                                               'preg_match'
          9        SEND_VAL                                                 '%23%28.%2A%29%5C%28%28.%2A%29%5C%29%23'
         10        SEND_VAR                                                 !0
         11        SEND_REF                                                 !1
         12        DO_ICALL                                                 
   15    13        INIT_FCALL                                               'preg_match'
         14        SEND_VAL                                                 '%23if%5C%28%28.%2A%29%5C%29+%5C%7B%28.%2A%29%5C%7D%23s'
         15        SEND_VAR                                                 !0
         16        SEND_REF                                                 !3
         17        DO_ICALL                                                 
   16    18      > JMPZ_EX                                          ~12     !3, ->21
         19    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~13     !3, 0
         20        BOOL                                             ~12     ~13
         21    > > JMPZ                                                     ~12, ->25
         22    >   INIT_METHOD_CALL                                         'conditions_ifelse'
         23        SEND_VAR_EX                                              !3
         24        DO_FCALL                                      0          
   17    25    > > JMPZ_EX                                          ~15     !1, ->28
         26    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~16     !1, 0
         27        BOOL                                             ~15     ~16
         28    > > JMPZ                                                     ~15, ->32
         29    >   INIT_METHOD_CALL                                         'calls'
         30        SEND_VAR_EX                                              !1
         31        DO_FCALL                                      0          
   18    32    > > 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/uth5B
function name:  calls
number of ops:  13
compiled vars:  !0 = $calls
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        FETCH_DIM_R                                      ~1      !0, 1
   21     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
   23    12      > RETURN                                                   null

End of function calls

Function condition_ifelse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uth5B
function name:  condition_ifelse
number of ops:  10
compiled vars:  !0 = $conditions
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%23%28.%2A%29%28%3D%3D%7C%3D%3D%3D%7C%5C%3C%7C%5C%3C%3D%7C%5C%3E%7C%5C%3E%3D%7C%21%3D%7C%21%3D%3D%7C%26%26%7C%5C%7C%5C%7C%7CAND%7COR%7CXOR%29%28.%2A%29%23i'
          3        FETCH_DIM_R                                      ~1      !0, 1
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        BOOL_NOT                                         ~3      $2
          7      > JMPZ                                                     ~3, ->9
          8    > > EXIT                                                     'Condition+parsing+error.'
   26     9    > > RETURN                                                   null

End of function condition_ifelse

End of class interpreter.

Class lang: [no user functions]
Class console: [no user functions]
Class out:
Function println:
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/uth5B
function name:  println
number of ops:  14
compiled vars:  !0 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     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
   37    12    >   ECHO                                                     !0
   38    13      > RETURN                                                   null

End of function println

End of class out.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.04 ms | 1404 KiB | 17 Q