3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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));
Output for 5.2.5 - 7.1.0
Notice: Undefined variable: rhs in /in/klWqN on line 10 Warning: explode(): Empty delimiter in /in/klWqN on line 10 Warning: array_map(): Argument #2 should be an array in /in/klWqN on line 11 Array ( [Term [+-] Exp | Term] => Array ( [0] => ) )
Output for 5.0.4 - 5.2.4
Notice: Undefined variable: rhs in /in/klWqN on line 10 Warning: explode(): Empty delimiter. in /in/klWqN on line 10 Warning: array_map(): Argument #2 should be an array in /in/klWqN on line 11 Array ( [Term [+-] Exp | Term] => Array ( [0] => ) )
Output for 4.3.2 - 5.0.3
Notice: Undefined variable: rhs in /in/klWqN on line 10 Warning: explode(): Empty delimiter. in /in/klWqN on line 10 Warning: array_map(): Argument #2 should be an array in /in/klWqN on line 11 Array ( [Term [+-] Exp | Term] => Array ( [0] => ) )
Output for 4.3.0 - 4.3.1
Notice: Undefined variable: rhs in /in/klWqN on line 10 Warning: explode() [http://www.php.net/function.explode]: Empty delimiter. in /in/klWqN on line 10 Warning: array_map() [http://www.php.net/function.array-map]: Argument #2 should be an array in /in/klWqN on line 11 Array ( [Term [+-] Exp | Term] => Array ( [0] => ) )