function prologList($string) { if ($string != '') { if ($string[0] == '[') { $string = prologPredicate::__cutOuterBrackets($string); $vars = prologPredicate::__separateStringPredicateVars($string); $this->listValues = prologPredicate::__convertStringsToObjects($vars); $this->charArray = false; } else { $this->charArray = true; for ($index = 0; $index < strlen($string); $index++) { array_push($this->listValues, $string[$index]); } } } else { $this->charArray = true; for ($index = 0; $index < strlen($string); $index++) { array_push($this->listValues, $string[$index]); } } }
/** * @return Array(PrologPredicate) * @param $predicateList String * @param $predicateName String * @param $predicateObject PrologPredicate * @desc Converts a prolog predicate string list into an array of each predicate object */ function seperatePredicateList($predicateList, $predicateName, $predicateObject) { $predicateListArray = array(); $predicateListArray = explode(",{$predicateName}", $predicateList); //Strip the first reference to the predicateName $predicateListArray[0] = preg_replace("/{$predicateName}/", "", $predicateListArray[0]); for ($index = 0; $index < sizeof($predicateListArray); $index++) { //Remove any white space $predicateListArray[$index] = preg_replace("/\\s/", "h", $predicateListArray[$index]); //Remove redundant first and last bracket $predicateListArray[$index] = prologPredicate::__cutOuterBrackets($predicateListArray[$index]); //Find all variables of predicate $predicateVars = prologPredicate::__separateStringPredicateVars($predicateListArray[$index]); //Recursively convert them into relevant objects $predicateValObjects = prologPredicate::__convertStringsToObjects($predicateVars); if ($predicateObject) { //Create Base predicate $predicateObject->setPredicateName($predicateName); $predicateObject->setPredicateValues($predicateValObjects); $predicate = $predicateObject; } else { $predicate = new prologPredicate($predicateName, $predicateValObjects); } //echo $predicate->toString(); $predicateListArray[$index] = $predicate; } return $predicateListArray; }