aboutsummaryrefslogtreecommitdiffstats
path: root/libnormalform_expression_to_term__.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnormalform_expression_to_term__.c')
-rw-r--r--libnormalform_expression_to_term__.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/libnormalform_expression_to_term__.c b/libnormalform_expression_to_term__.c
new file mode 100644
index 0000000..af988ea
--- /dev/null
+++ b/libnormalform_expression_to_term__.c
@@ -0,0 +1,82 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifndef TEST
+
+
+int
+(libnormalform_expression_to_term__)(struct libnormalform_term *out, struct expression *this)
+{
+ size_t i;
+
+ out->type = this->type;
+ out->reduced = this->reduced;
+
+ switch (this->type) {
+ case LIBNORMALFORM_CONJUNCTION:
+ case LIBNORMALFORM_DISJUNCTION:
+ case LIBNORMALFORM_EXCLUSIVE_DISJUNCTION:
+ out->term.clause.nterms = 0;
+ out->term.clause.terms = calloc(this->nterms, sizeof(*out->term.clause.terms));
+ if (!out->term.clause.terms)
+ return -1;
+ for (i = 0; i < this->nterms; i++)
+ if (libnormalform_expression_to_term__(&out->term.clause.terms[out->term.clause.nterms++], this->terms[i]))
+ return -1;
+ break;
+
+ case LIBNORMALFORM_TRANSFORMATION:
+ out->term.transformation.transformer = this->user_item;
+ out->term.transformation.sentence = calloc(1, sizeof(*out->term.transformation.sentence));
+ if (!out->term.transformation.sentence ||
+ libnormalform_expression_to_term__(out->term.transformation.sentence, this->terms[0]))
+ return -1;
+ break;
+
+ case LIBNORMALFORM_VARIABLE:
+ case LIBNORMALFORM_NEGATED_VARIABLE:
+ out->term.variable = this->user_item;
+ break;
+
+ case LIBNORMALFORM_FUNCTION:
+ case LIBNORMALFORM_NEGATED_FUNCTION:
+ out->term.function = this->user_item;
+ break;
+
+ case LIBNORMALFORM_FOR_ALL:
+ case LIBNORMALFORM_NEGATED_FOR_ALL:
+ case LIBNORMALFORM_FOR_ANY:
+ case LIBNORMALFORM_NEGATED_FOR_ANY:
+ case LIBNORMALFORM_FOR_ONE:
+ case LIBNORMALFORM_NEGATED_FOR_ONE:
+ out->term.qualification.domain = this->user_item;
+ if (this->nterms == 1) {
+ out->term.qualification.antecedent = NULL;
+ out->term.qualification.predicate = calloc(1, sizeof(*out->term.qualification.predicate));
+ if (!out->term.qualification.predicate ||
+ libnormalform_expression_to_term__(out->term.qualification.predicate, this->terms[0]))
+ return -1;
+ } else {
+ out->term.qualification.antecedent = calloc(1, sizeof(*out->term.qualification.antecedent));
+ if (!out->term.qualification.antecedent)
+ return -1;
+ out->term.qualification.predicate = calloc(1, sizeof(*out->term.qualification.predicate));
+ if (!out->term.qualification.predicate ||
+ libnormalform_expression_to_term__(out->term.qualification.antecedent, this->terms[0]) ||
+ libnormalform_expression_to_term__(out->term.qualification.predicate, this->terms[1]))
+ return -1;
+ }
+ break;
+
+ default:
+ abort();
+ }
+
+ return 0;
+}
+
+
+#else
+
+TODO_TEST
+
+#endif