-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.c
61 lines (48 loc) · 1.02 KB
/
node.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Interface that handles SPL nodes.
*/
#include "node.h"
#include <stdlib.h>
#include <string.h>
/* Creates a terminal node */
node *create_termNode(char nodetype, char *name, int value)
{
node *tnode = malloc(sizeof(node));
if (name != NULL)
tnode->name = strdup(name);
tnode->nodetype = nodetype;
tnode->value = value;
tnode->ptr1 = NULL;
tnode->ptr2 = NULL;
tnode->ptr3 = NULL;
return tnode;
}
/* Creates a non-terminal node */
node *create_nontermNode(char nodetype, node *a, node *b)
{
node *temp = malloc(sizeof(node));
temp->nodetype = nodetype;
temp->name = NULL;
temp->ptr1 = a;
temp->ptr2 = b;
temp->ptr3 = NULL;
return temp;
}
/* Retrieves the node type */
char node_getType(node *nn)
{
return nn->nodetype;
}
/* Retrieves the node name */
char *node_getName(node *nn)
{
return nn->name;
}
/* Assigns the tree pointers */
node *create_tree(node *a, node *b, node *c, node *d)
{
a->ptr1 = b;
a->ptr2 = c;
a->ptr3 = d;
return a;
}