Exemplo n.º 1
0
 function is_acceptable($input)
 {
     return compare_syntax3($this->expr, $input, nano_dfdict(), true) !== NULL;
 }
Exemplo n.º 2
0
}
if ($cquiz->mode() != "question") {
    exit("Checking answers is not allowed for this quiz (mode: " . $cquiz->mode() . ")");
}
$flags = ["unescaped" => TRUE, "matchall" => TRUE];
$name = safe_get("name", $_POST);
if (!$name) {
    exit("no key name supplied");
}
$values = $cquiz->answers()[$name];
$answer = safe_get("answer", $_POST);
if (!$answer) {
    exit("no answer supplied");
}
if (array_key_exists("correct", $values) and is_array($values["correct"]) and array_key_exists("expr", $values) and is_string($values["expr"])) {
    $value = compare_syntax3($values["expr"], $answer, nano_dfdict(), true);
    if ($value === null) {
        echo "false";
    } else {
        echo "true";
    }
} else {
    if (array_key_exists("correct", $values) and array_key_exists("acceptable", $values) and is_array($values["correct"]) and is_array($values["acceptable"])) {
        $also = $values["correct"];
        $correct = $values["correct"];
        $values = $values["acceptable"];
    } else {
        $correct = $also = $values;
    }
    $score = FALSE;
    foreach ($values as $value) {
Exemplo n.º 3
0
<?php

require_once '/var/www/config.php';
sro('/Includes/mysql.php');
sro('/Includes/session.php');
sro('/Includes/functions.php');
sro('/PHP5/lib/PHPLang/common.php');
sro('/PHP5/lib/PHPLang/display.php');
sro('/PHP5/lib/PHPLang/string.php');
sro('/PHP5/lib/PHPLang/misc.php');
$input = $_GET["input"];
$syntax = $_GET["syntax"];
$dict = nano_dfdict();
global $DEBUG_STRING_PHP;
$expression = nanomacro($syntax, $dict, 4);
$DEBUG_STRING_PHP = safe_get("debug", $_GET) === "true";
$permutation = permute_syntax($expression);
ob_start();
$result = compare_syntax3($syntax, $input, $dict, !!safe_get("matchall", $_GET), safe_get("dist", $_GET));
$log = ob_get_contents();
ob_end_clean();
echo json_encode(["expression" => $expression, "result" => $result, "log" => $log, "permutation" => $permutation]);
Exemplo n.º 4
0
function compare_syntax3($syntax, $target, $dictionary = null, $matchall = false, $distance = 0, $lang = NULL)
{
    if ($dictionary === null) {
        $dictionary = nano_dfdict();
    }
    $syntax = nanomacro($syntax, $dictionary, 4);
    $match = compare_syntax($syntax, $target, ["unescaped" => true, "matchall" => $matchall, "max_distance" => $distance, "lang" => $lang]);
    return $match ? normalize_punctuation($match) : $match;
}