3v4l.org

run code in 300+ PHP versions simultaneously
<?php function grammar($description) { $g=array(); foreach(explode("\n",$description) as $line) { $sides = explode(" => ",$line); $lhs = $sides[0]; $lhs = $sides[1]; $alternatives = explode($rhs,' | '); $g[$lhs] = array(array_map("explode",$alternatives,array(" "))); } return $g; } $des =<<<G Exp => Term [+-] Exp | Term G; print_r(grammar($des));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/klWqN
function name:  (null)
number of ops:  8
compiled vars:  !0 = $des
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                   !0, 'Exp+%3D%3E+Term+%5B%2B-%5D+Exp+%7C+Term'
   18     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'grammar'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function grammar:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 31
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 31
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/klWqN
function name:  grammar
number of ops:  34
compiled vars:  !0 = $description, !1 = $g, !2 = $line, !3 = $sides, !4 = $lhs, !5 = $alternatives, !6 = $rhs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%0A'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $8      
          6      > FE_RESET_R                                       $9      $8, ->31
          7    > > FE_FETCH_R                                               $9, !2, ->31
    7     8    >   INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '+%3D%3E+'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !3, $10
    8    13        FETCH_DIM_R                                      ~12     !3, 0
         14        ASSIGN                                                   !4, ~12
    9    15        FETCH_DIM_R                                      ~14     !3, 1
         16        ASSIGN                                                   !4, ~14
   10    17        INIT_FCALL                                               'explode'
         18        SEND_VAR                                                 !6
         19        SEND_VAL                                                 '+%7C+'
         20        DO_ICALL                                         $16     
         21        ASSIGN                                                   !5, $16
   11    22        INIT_FCALL                                               'array_map'
         23        SEND_VAL                                                 'explode'
         24        SEND_VAR                                                 !5
         25        SEND_VAL                                                 <array>
         26        DO_ICALL                                         $19     
         27        INIT_ARRAY                                       ~20     $19
         28        ASSIGN_DIM                                               !1, !4
         29        OP_DATA                                                  ~20
    5    30      > JMP                                                      ->7
         31    >   FE_FREE                                                  $9
   13    32      > RETURN                                                   !1
   14    33*     > RETURN                                                   null

End of function grammar

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.75 ms | 1394 KiB | 20 Q