#include <stdio.h>Go to the source code of this file.
Typedefs | |
| typedef void * | boolexpr_t |
| Cookie type for an expression tree node. | |
Enumerations | |
| enum | bool_operator_t { BOOLSTUFF_VALUE, BOOLSTUFF_AND, BOOLSTUFF_OR, BOOLSTUFF_NOT } |
| Possible types of a node. More... | |
| enum | bool_error_t { BOOLSTUFF_OK, BOOLSTUFF_ERR_GARBAGE_AT_END, BOOLSTUFF_ERR_RUNAWAY_PARENTHESIS, BOOLSTUFF_ERR_STRING_EXPECTED } |
| Possible error codes returned by the parser. More... | |
Functions | |
| boolexpr_t | boolstuff_create_value_node (const char *value) |
| Creates a node that contains a copy of the designated string as its value. | |
| boolexpr_t | boolstuff_create_operator_node (enum bool_operator_t op, boolexpr_t left, boolexpr_t right) |
| Creates a node that represents a boolean operator. | |
| boolexpr_t | boolstuff_parse (const char *expr, size_t *error_index, enum bool_error_t *error_code) |
| Parse a textual boolean expression and creates a binary tree. | |
| void | boolstuff_destroy_tree (boolexpr_t root) |
| Destroys a tree and all its dynamically allocated nodes. | |
| enum bool_operator_t | boolstuff_get_node_type (boolexpr_t node) |
| Returns of type of the node (value or operator). | |
| const char * | boolstuff_get_node_value (boolexpr_t node) |
| Returns the value of node that represents a variable. | |
| boolexpr_t | boolstuff_get_left_subtree (boolexpr_t node) |
| Returns the root of the left-hand subtree of a node. | |
| boolexpr_t | boolstuff_get_right_subtree (boolexpr_t node) |
| Returns the root of the right-hand subtree of a node. | |
| void | boolstuff_set_node_type (boolexpr_t node, enum bool_operator_t op) |
| Sets the type of a node. | |
| void | boolstuff_set_left_subtree (boolexpr_t node, boolexpr_t subtree) |
| Attaches a subtree as a node's left-hand subtree. | |
| void | boolstuff_set_right_subtree (boolexpr_t node, boolexpr_t subtree) |
| Attaches a subtree as this node's right-hand subtree. | |
| void | boolstuff_set_node_value (boolexpr_t node, const char *value) |
| Changes the string value of a node. | |
| void | boolstuff_print_tree (FILE *out, boolexpr_t root) |
| Prints a boolean expression tree in a file. | |
| char * | boolstuff_print_tree_to_string (boolexpr_t root) |
| void | boolstuff_free_string (char *s) |
| Frees the memory used by a string created by this library. | |
| boolexpr_t | boolstuff_clone_tree (boolexpr_t root) |
| Creates a complete copy of a binary tree. | |
| boolexpr_t | boolstuff_get_disjunctive_normal_form (boolexpr_t root) |
| Transforms a tree into the Disjunctive Normal Form. | |
| int | boolstuff_is_disjunctive_normal_form (boolexpr_t root) |
| Determines if a tree is in Disjunctive Normal Form. | |
| boolexpr_t * | boolstuff_get_dnf_term_roots (boolexpr_t root, size_t *num) |
| Returns the terms of a tree in Disjunctive Normal Form. | |
| void | boolstuff_free_node_array (boolexpr_t *array) |
| Frees an array returned by boolstuff_get_dnf_term_roots(). | |
| void | boolstuff_get_tree_variables (boolexpr_t tree, char ***positivesArray, char ***negativesArray) |
| void | boolstuff_free_variables_sets (char **positivesArray, char **negativesArray) |
| Frees the arrays created by boolstuff_get_tree_variables(). | |
| typedef void* boolexpr_t |
Cookie type for an expression tree node.
The NULL value represents the absence of a node.
| enum bool_error_t |
| enum bool_operator_t |
| boolexpr_t boolstuff_clone_tree | ( | boolexpr_t | root | ) |
Creates a complete copy of a binary tree.
| root | root of the tree to be cloned |
| boolexpr_t boolstuff_create_operator_node | ( | enum bool_operator_t | op, | |
| boolexpr_t | left, | |||
| boolexpr_t | right | |||
| ) |
Creates a node that represents a boolean operator.
| op | type of operator | |
| left | left-hand child to attach to the created node (when creating a node of type BOOLSTUFF_NOT, pass NULL for 'left') | |
| right | right-hand child to attach to the created node |
| boolexpr_t boolstuff_create_value_node | ( | const char * | value | ) |
Creates a node that contains a copy of the designated string as its value.
| value | string to use as the node value (if NULL, an empty string is used as the node value) |
| void boolstuff_destroy_tree | ( | boolexpr_t | root | ) |
Destroys a tree and all its dynamically allocated nodes.
| root | root of the tree to be destroyed |
| void boolstuff_free_node_array | ( | boolexpr_t * | array | ) |
Frees an array returned by boolstuff_get_dnf_term_roots().
| array | array to be freed (ignored if NULL) |
| void boolstuff_free_string | ( | char * | s | ) |
Frees the memory used by a string created by this library.
| s | the address of the string to be freed |
| void boolstuff_free_variables_sets | ( | char ** | positivesArray, | |
| char ** | negativesArray | |||
| ) |
Frees the arrays created by boolstuff_get_tree_variables().
| positivesArray | array of positive variables values | |
| negativesArray | array of negative variables values |
| boolexpr_t boolstuff_get_disjunctive_normal_form | ( | boolexpr_t | root | ) |
Transforms a tree into the Disjunctive Normal Form.
| root | root of the tree to transform |
| boolexpr_t* boolstuff_get_dnf_term_roots | ( | boolexpr_t | root, | |
| size_t * | num | |||
| ) |
Returns the terms of a tree in Disjunctive Normal Form.
The tree must be in DNF. The nodes of the returned trees must not be modified. boolstuff_free_node_array() MUST be called afterwards on the returned array pointer to free the allocated memory.
| root | root of the DNF tree of which to return the terms | |
| num | pointer to a size_t that receives the number of non-null pointers in the returned array (ignored if NULL) |
| boolexpr_t boolstuff_get_left_subtree | ( | boolexpr_t | node | ) |
Returns the root of the left-hand subtree of a node.
| node | node of which to return the left-hand subtree |
| enum bool_operator_t boolstuff_get_node_type | ( | boolexpr_t | node | ) |
Returns of type of the node (value or operator).
| node | node of which to return the type |
| const char* boolstuff_get_node_value | ( | boolexpr_t | node | ) |
Returns the value of node that represents a variable.
| node | node that must be of type BOOLSTUFF_VALUE |
| boolexpr_t boolstuff_get_right_subtree | ( | boolexpr_t | node | ) |
Returns the root of the right-hand subtree of a node.
| node | node of which to return the right-hand subtree |
| void boolstuff_get_tree_variables | ( | boolexpr_t | tree, | |
| char *** | positivesArray, | |||
| char *** | negativesArray | |||
| ) |
| int boolstuff_is_disjunctive_normal_form | ( | boolexpr_t | root | ) |
Determines if a tree is in Disjunctive Normal Form.
| root | root of the tree to examine |
| boolexpr_t boolstuff_parse | ( | const char * | expr, | |
| size_t * | error_index, | |||
| enum bool_error_t * | error_code | |||
| ) |
Parse a textual boolean expression and creates a binary tree.
| expr | boolean expression to parse (must not be NULL) | |
| error_index | pointer to a size_t that will receive the index in 'expr' where the error was detected (ignored if NULL) | |
| error_code | pointer to an 'enum bool_error_t' that will receive the error code (ignored if NULL) |
| void boolstuff_print_tree | ( | FILE * | out, | |
| boolexpr_t | root | |||
| ) |
Prints a boolean expression tree in a file.
| out | file in which to write the boolean expression | |
| root | root node of the boolean expression tree to write |
| char* boolstuff_print_tree_to_string | ( | boolexpr_t | root | ) |
| void boolstuff_set_left_subtree | ( | boolexpr_t | node, | |
| boolexpr_t | subtree | |||
| ) |
Attaches a subtree as a node's left-hand subtree.
| node | node that becomes the parent | |
| subtree | root of the tree that becomes the left-hand subtree |
| void boolstuff_set_node_type | ( | boolexpr_t | node, | |
| enum bool_operator_t | op | |||
| ) |
Sets the type of a node.
| node | node whose type is to be set | |
| op | new type of this node |
| void boolstuff_set_node_value | ( | boolexpr_t | node, | |
| const char * | value | |||
| ) |
Changes the string value of a node.
| node | node whose value is to be changed | |
| value | string that becomes the node's new value (must not be NULL) |
| void boolstuff_set_right_subtree | ( | boolexpr_t | node, | |
| boolexpr_t | subtree | |||
| ) |
Attaches a subtree as this node's right-hand subtree.
| node | node that becomes the parent | |
| subtree | root of the tree that becomes the right-hand subtree |
1.5.9