This commit is contained in:
Wiesner András 2025-10-14 14:30:45 +02:00
parent cd4048a0b5
commit 4814c357eb
2 changed files with 14 additions and 4 deletions

View File

@ -15,6 +15,11 @@ class LogicFunction implements JsonSerializable
return str_replace(["/", "!", "*", "+"], ["~", "~", "&", "|"], $expression);
}
public static function adaptToEL(string $expression): string
{
return str_replace(["~"], [" not "], $expression);
}
public static function collectVariables(string $expression): array
{
preg_match_all("/\w/", $expression, $variables);
@ -41,7 +46,7 @@ class LogicFunction implements JsonSerializable
$vars[$var] = 0;
}
$expression = $this->getExpression("verilog_logic");
$expression = self::adaptToEL($this->getExpression("verilog_logic"));
// printf("Cooked: %s\n", $cooked_form);
$tt = [];
@ -171,7 +176,7 @@ class LogicFunction implements JsonSerializable
public function isValid(): bool
{
try {
self::$EXP_LANG->lint($this->expression, $this->input_vars);
self::$EXP_LANG->lint(self::adaptToEL($this->expression), $this->input_vars);
} catch (Exception $e) {
return false;
}
@ -248,9 +253,10 @@ class LogicFunction implements JsonSerializable
return join(" | ", $minterms);
}
public function drawNetwork(string $outvar = "f"): string {
public function drawNetwork(string $outvar = "f"): string
{
$expr = str_replace(["^"], [" xor "], $this->getExpression());
return PythonUtils::execPy("draw_logic_network.py", [ $expr, $outvar ]);
return PythonUtils::execPy("draw_logic_network.py", [$expr, $outvar]);
}
}

View File

@ -27,6 +27,10 @@ class SingleChoiceTask extends PicturedTask
$this->answers[] = $answer;
}
function clearAnswers(): void {
$this->answers = [];
}
function getAnswers(): array
{
return $this->answers;