P_Node new_node_key(key)

- creates a new node of type KEY int key;

P_Node new_node_gi(str)

- creates a new node of type GI String str;

P_Node new_node_group()

- creates a new node of type GROUP

P_Node create_node(type, occ)

- creates a node of type type with occurrence indicator occ int type; int occ;

void delete_node(node)

- delete node P_Node node;

The content model of an element declaration is stored into a tree-structure. This tree-structure is represented by the node datatype `P_Node'. In the tree, each node corresponds to a content token in the content model. A node can be of any type in {KEY, GI, GROUP, GI_START, GI_NAME, GI_END}.
For a keyword in a content model, the node is a leaf with type KEY. The key-field of a KEY node determines which kind of KEY it is: this must be one of {ANY, CDATA, PCDATA, EMPTY, PCDATA, XPCDATA}.
A generic identifier in a content model a node of type GI is created. This node always has three children: GI_START, GI_NAME and GI_END, which respectively stand for the starttag, the content and the endtag.
A SEQ-group, AND-group or OR-group is represented by a node of type GROUP. The group_type of such a node determines which kind of group it is: this must be one of {SEQ, AND, OR}.
The first three functions above create a new node of the given type. Memory is allocated, the node is initialized and a pointer to the node-structure is returned. new_node_gi() creates a GI-node, and also creates its three children. These children cannot be created separately. create_node() is a local function, called by the other three, to perform the actual allocation and initialization. delete_node() deletes node. If node has children, the children are not deleted, except if the children represent the starttag and endtag of node.

int combine_occ(occ1, occ2)

- merge the two occurrences int occ1; int occ2;

The two occurrence are combined to one occurrence indicator. If occ1 is NO_OCC, the result is occ2 and v.v. If one of them is OCC_REP, the result is OCC_REP. If the occurence of one of them is OCC_PLUS and the other is OCC_OPT, then the result is OCC_REP, otherwise OCC_PLUS.

void node_add(node, a)

- adds a child at the end of a group-node P_Node node; P_Node a;

The function node_add() adds a node to another node. This is the only function through which a tree can be build. A node can only be added to a GROUP-node. Other nodes have no children.

void node_set_key(node, key)

- sets the key value of node P_Node node; int key;

void node_set_occ(node, occ)

- sets the occurrence indicator of node P_Node node; int occ;

void node_set_group_type(node, type)

- sets the group type of node P_Node node; int type;

void node_set_status(node, s)

- set the status of node P_Node node; int s;

void node_set_flagin(node, f)

- set the in flag, used for starttag omission P_Node node; int f;

void node_set_flagout(node, f)

- set the out flag, used for starttag omission P_Node node; int f;

void node_set_nullable(node, null)

- set the nullable status of node P_Node node; int null;

void node_set_busy(node, b)

- sets busy flag, used by ambiguity checker P_Node node; Bool b;

void node_set_done(node, b)

- sets done flag, used by ambiguity checker P_Node node; Bool b;

void node_set_firstsym(node, s)

- sets the set of firstsymbols, used by ambiguity checker P_Node node; P_Set s;

void node_set_followsym(node, s)

- sets the set of followsymbols, used by ambiguity checker P_Node node; P_Set s;

The node_set_... functions set the value of the corresponding field in the node. Checks are done to see whether the value is allowed for the particular type of node.

P_Group node_group(node)

- returns the group of the children of node P_Node node;

P_Node node_parent(node)

- returns the parent of node P_Node node;

int node_type(node)

- returns the type of node P_Node node;

String node_gi(node)

- returns the generic identifier of node P_Node node;

int node_key(node)

- returns the key of node P_Node node;

int node_occ(node)

- returns the occurrence indicator of node P_Node node;

int node_status(node)

- returns the status of node P_Node node;

int node_flagin(node)

- returns the in flag of node P_Node node;

int node_flagout(node)

- returns the out flag of node P_Node node;

int node_nullable(node)

- returns the nullable indicator of node P_Node node;

Bool node_busy(node)

- returns busy flag, used by ambiguity checker P_Node node;

Bool node_done(node)

- returns done flag, used by ambiguity checker P_Node node;

P_Set node_firstsym(node)

- returns the set of firstsymbols P_Node node;

P_Set node_followsym(node)

- returns the set of followsymbols P_Node node;

These node_... functions return the value of the corresponding field in the node. For `P_Group', see ``group.c''.

void node_traverse_post(node, action, elem)

- traverses tree post-order P_Node node; P_Node_func action; P_Element elem;

void node_traverse_pre(node, action, elem)

- traverses tree pre-order P_Node node; P_Node_func action; P_Element elem;

These functions travel through the tree of which node is the root. In each visited node the function action is executed, with node and elem as parameters. The order in which node_traverse_post() traverses the tree is: first the children, then the node (depth first). The order in which node_traverse_pre() traverses the tree is: first the node, then its children (breadth first).

void set_converted_parents(node)

- sets parent field for converted node P_Node node;

void node_convert_plus(node)

- converts PLUS-node to STAR-node P_Node node;

A node with occurrence indicator PLUS is converted into a node with occurrence indicator STAR.
    (elem)+   becomes   (elem, (elem)*)
This recognizes the same document, but it is easier to use with contextual required elements.
A new copy of the tree of which node is the root, is made. In making the copy, the parent fields of the node and the copy becomes invalid, because a SEQ group is added above node.
set_converted_parents() sets the value of the parent fields of the children of node to node.

void node_put(file, n)

- prints node-tree on a file FILE *file; P_Node n;

void node_write(file, n)

- prints node-tree on a file FILE *file; P_Node n;

void node_print(file, n)

- prints node-tree on a file FILE *file; P_Node n;

String type_to_string(t)

- returns string representation of t int t;

void indent(file)

- prints indentation on file FILE *file;

The functions node_put(), node_write(), node_print() are three different ways of printing the tree of which node is the root. The function indent() is used to get proper indentation while printing a tree. The function type_to_string() returns a string representation of the type of a node. It is only used in the tree-printing functions. These functions are only used for debugging purposes.

P_Node node_assign(node)

- creates a newly allocated copy of node P_Node node;

P_Node node_copy(node)

- creates a new copy of the tree of which node is the root P_Node node;

These functions are straight forward. node_assign() creates a new node, in which all values are set to the values of node. node_copy() creates a new copy of the complete tree of which node is the root. If node has children node_copy() calls itself recursively for each child.

node.c node.h