3v4l.org

run code in 500+ PHP versions simultaneously
<?php $expression = "5+4^3^2^1"; if (!preg_match('~^-?\d*\.?\d+([*/+-^]-?\d*\.?\d+)*$~', $expression)) { echo "invalid expression"; } else { $components = preg_split('~(?<=\d)([*/+-^])~', $expression, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); var_export($components); // ['5','+','4','^','3','^','2','^','1'] while (($index = array_search('^', $components)) !== false) { array_splice($components, $index - 1, 3, pow($components[$index - 1], $components[$index + 1])); var_export($components); // ['5', '+', 64, '^', '2', '^', '1'] // ['5', '+' ,4096, '^', '1'] // ['5', '+', 4096] } while (($index = array_search('*', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] * $components[$index + 1]); var_export($components); } while (($index = array_search('/', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] / $components[$index + 1]); } while (($index = array_search('+', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] + $components[$index + 1]); // [4101] } while (($index = array_search('-', $components)) !== false) { array_splice($components, $index - 1, 3, $components[$index - 1] - $components[$index + 1]); } echo $components[0]; // 4101 }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 127
Branch analysis from position: 127
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 17
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 43
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 66
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
2 jumps found. (Code = 44) Position 1 = 105, Position 2 = 86
Branch analysis from position: 105
1 jumps found. (Code = 42) Position 1 = 118
Branch analysis from position: 118
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 106
Branch analysis from position: 125
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 106
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 106
Branch analysis from position: 125
Branch analysis from position: 106
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 105, Position 2 = 86
Branch analysis from position: 105
Branch analysis from position: 86
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 66
Branch analysis from position: 85
Branch analysis from position: 66
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 43
Branch analysis from position: 65
Branch analysis from position: 43
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 17
Branch analysis from position: 42
Branch analysis from position: 17
filename:       /in/c5PIX
function name:  (null)
number of ops:  128
compiled vars:  !0 = $expression, !1 = $components, !2 = $index
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '5%2B4%5E3%5E2%5E1'
    4     1        FRAMELESS_ICALL_2                preg_match          ~4      '%7E%5E-%3F%5Cd%2A%5C.%3F%5Cd%2B%28%5B%2A%2F%2B-%5E%5D-%3F%5Cd%2A%5C.%3F%5Cd%2B%29%2A%24%7E', !0
          2        BOOL_NOT                                             ~5      ~4
          3      > JMPZ                                                         ~5, ->6
    5     4    >   ECHO                                                         'invalid+expression'
    4     5      > JMP                                                          ->127
    7     6    >   INIT_FCALL                                                   'preg_split'
          7        SEND_VAL                                                     '%7E%28%3F%3C%3D%5Cd%29%28%5B%2A%2F%2B-%5E%5D%29%7E'
          8        SEND_VAR                                                     !0
          9        SEND_VAL                                                     0
         10        SEND_VAL                                                     3
         11        DO_ICALL                                             $6      
         12        ASSIGN                                                       !1, $6
    8    13        INIT_FCALL                                                   'var_export'
         14        SEND_VAR                                                     !1
         15        DO_ICALL                                                     
    9    16      > JMP                                                          ->35
   10    17    >   INIT_FCALL                                                   'array_splice'
         18        SEND_REF                                                     !1
         19        SUB                                                  ~9      !2, 1
         20        SEND_VAL                                                     ~9
         21        SEND_VAL                                                     3
         22        INIT_FCALL                                                   'pow'
         23        SUB                                                  ~10     !2, 1
         24        FETCH_DIM_R                                          ~11     !1, ~10
         25        SEND_VAL                                                     ~11
         26        ADD                                                  ~12     !2, 1
         27        FETCH_DIM_R                                          ~13     !1, ~12
         28        SEND_VAL                                                     ~13
         29        DO_ICALL                                             $14     
         30        SEND_VAR                                                     $14
         31        DO_ICALL                                                     
   11    32        INIT_FCALL                                                   'var_export'
         33        SEND_VAR                                                     !1
         34        DO_ICALL                                                     
    9    35    >   INIT_FCALL                                                   'array_search'
         36        SEND_VAL                                                     '%5E'
         37        SEND_VAR                                                     !1
         38        DO_ICALL                                             $17     
         39        ASSIGN                                               ~18     !2, $17
         40        TYPE_CHECK                                      1018          ~18
         41      > JMPNZ                                                        ~19, ->17
   16    42    > > JMP                                                          ->58
   17    43    >   INIT_FCALL                                                   'array_splice'
         44        SEND_REF                                                     !1
         45        SUB                                                  ~20     !2, 1
         46        SEND_VAL                                                     ~20
         47        SEND_VAL                                                     3
         48        SUB                                                  ~21     !2, 1
         49        FETCH_DIM_R                                          ~22     !1, ~21
         50        ADD                                                  ~23     !2, 1
         51        FETCH_DIM_R                                          ~24     !1, ~23
         52        MUL                                                  ~25     ~22, ~24
         53        SEND_VAL                                                     ~25
         54        DO_ICALL                                                     
   18    55        INIT_FCALL                                                   'var_export'
         56        SEND_VAR                                                     !1
         57        DO_ICALL                                                     
   16    58    >   INIT_FCALL                                                   'array_search'
         59        SEND_VAL                                                     '%2A'
         60        SEND_VAR                                                     !1
         61        DO_ICALL                                             $28     
         62        ASSIGN                                               ~29     !2, $28
         63        TYPE_CHECK                                      1018          ~29
         64      > JMPNZ                                                        ~30, ->43
   20    65    > > JMP                                                          ->78
   21    66    >   INIT_FCALL                                                   'array_splice'
         67        SEND_REF                                                     !1
         68        SUB                                                  ~31     !2, 1
         69        SEND_VAL                                                     ~31
         70        SEND_VAL                                                     3
         71        SUB                                                  ~32     !2, 1
         72        FETCH_DIM_R                                          ~33     !1, ~32
         73        ADD                                                  ~34     !2, 1
         74        FETCH_DIM_R                                          ~35     !1, ~34
         75        DIV                                                  ~36     ~33, ~35
         76        SEND_VAL                                                     ~36
         77        DO_ICALL                                                     
   20    78    >   INIT_FCALL                                                   'array_search'
         79        SEND_VAL                                                     '%2F'
         80        SEND_VAR                                                     !1
         81        DO_ICALL                                             $38     
         82        ASSIGN                                               ~39     !2, $38
         83        TYPE_CHECK                                      1018          ~39
         84      > JMPNZ                                                        ~40, ->66
   23    85    > > JMP                                                          ->98
   24    86    >   INIT_FCALL                                                   'array_splice'
         87        SEND_REF                                                     !1
         88        SUB                                                  ~41     !2, 1
         89        SEND_VAL                                                     ~41
         90        SEND_VAL                                                     3
         91        SUB                                                  ~42     !2, 1
         92        FETCH_DIM_R                                          ~43     !1, ~42
         93        ADD                                                  ~44     !2, 1
         94        FETCH_DIM_R                                          ~45     !1, ~44
         95        ADD                                                  ~46     ~43, ~45
         96        SEND_VAL                                                     ~46
         97        DO_ICALL                                                     
   23    98    >   INIT_FCALL                                                   'array_search'
         99        SEND_VAL                                                     '%2B'
        100        SEND_VAR                                                     !1
        101        DO_ICALL                                             $48     
        102        ASSIGN                                               ~49     !2, $48
        103        TYPE_CHECK                                      1018          ~49
        104      > JMPNZ                                                        ~50, ->86
   27   105    > > JMP                                                          ->118
   28   106    >   INIT_FCALL                                                   'array_splice'
        107        SEND_REF                                                     !1
        108        SUB                                                  ~51     !2, 1
        109        SEND_VAL                                                     ~51
        110        SEND_VAL                                                     3
        111        SUB                                                  ~52     !2, 1
        112        FETCH_DIM_R                                          ~53     !1, ~52
        113        ADD                                                  ~54     !2, 1
        114        FETCH_DIM_R                                          ~55     !1, ~54
        115        SUB                                                  ~56     ~53, ~55
        116        SEND_VAL                                                     ~56
        117        DO_ICALL                                                     
   27   118    >   INIT_FCALL                                                   'array_search'
        119        SEND_VAL                                                     '-'
        120        SEND_VAR                                                     !1
        121        DO_ICALL                                             $58     
        122        ASSIGN                                               ~59     !2, $58
        123        TYPE_CHECK                                      1018          ~59
        124      > JMPNZ                                                        ~60, ->106
   30   125    >   FETCH_DIM_R                                          ~61     !1, 0
        126        ECHO                                                         ~61
   31   127    > > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
176.54 ms | 2083 KiB | 18 Q