+static Node *
+new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
+{
+ Node *node = (Node *) malloc (sizeof (Node));
+ node->nterm.isNterm = 1;
+ node->nterm.parents = 0;
+ node->nterm.form = form;
+ node->nterm.children[0] = child0;
+ if (child0)
+ child0->nodeInfo.parents += 1;
+ node->nterm.children[1] = child1;
+ if (child1)
+ child1->nodeInfo.parents += 1;
+ node->nterm.children[2] = child2;
+ if (child2)
+ child2->nodeInfo.parents += 1;
+ return node;
+}
+
+static Node *
+new_term (char *text)
+{
+ Node *node = (Node *) malloc (sizeof (Node));
+ node->term.isNterm = 0;
+ node->term.parents = 0;
+ node->term.text = text;
+ return node;
+}
+
+static void
+free_node (Node *node)
+{
+ if (!node)
+ return;
+ node->nodeInfo.parents -= 1;
+ /* Free only if 0 (last parent) or -1 (no parents). */
+ if (node->nodeInfo.parents > 0)
+ return;
+ if (node->nodeInfo.isNterm == 1)
+ {
+ free_node (node->nterm.children[0]);
+ free_node (node->nterm.children[1]);
+ free_node (node->nterm.children[2]);
+ }
+ else
+ free (node->term.text);
+ free (node);
+}