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]; $rhs = $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 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [Exp] => Array ( [0] => Array ( [0] => Array ( [0] => ) [1] => Array ( [0] => ) ) ) )