if (!empty($s1)) { $remainder = substr($input, strlen($s1)); $rightList = $this->interpret($remainder); // recursive call foreach ($rightList as $s2) { $result[] = $s1 . $s2; // php string concatenation } } } return $result; } } $a = Exp::Lit("a"); $b = Exp::Lit("b"); $c = Exp::Lit("c"); $aa = Exp::Conj($a, Exp::Many($a)); // one or more 'a' $bb = Exp::Conj($b, Exp::Many($b)); // one or more 'b' $cc = Exp::Conj($c, Exp::Many($c)); // one or more 'c' $regex = Exp::Many(Exp::Conj(Exp::Disj($aa, $bb), $cc)); $string = "acbbccaaacccbbbbaaaaaccccc"; echo "regex = " . $regex . "\n"; echo "string = \"" . $string . "\"\n"; echo "The recognized prefixes are:\n"; $result = []; for ($i = 0; $i <= strlen($string); ++$i) { $test = substr($string, 0, $i); if ($regex->recognize($test)) {