This repository was archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_tree.h
84 lines (61 loc) · 1.64 KB
/
parse_tree.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* File: parse_tree.h
* Creator: Adam Kaplan
* Time-stamp: October 19, 2016
* Project 2
*/
#ifndef PARSE_TREE
#define PARSE_TREE
#include "declarations.h"
/*
Create TreeNode and Tree objects
*/
typedef struct TreeNode {
BOOL isTerminal;
char *terminal;
char *label;
struct TreeNode *left;
struct TreeNode *center;
struct TreeNode *right;
} TreeNode;
typedef struct Tree {
TreeNode *root;
} Tree;
/*
Memory allocation functions
*/
TreeNode* tnalloc();
Tree* talloc();
/*
Init and Free functions
*/
TreeNode* TreeNode_new(BOOL isTerminal, char *label, char *terminal);
TreeNode* TreeNode_new_empty();
Tree* Tree_new(BOOL isTerminal, char *label, char *terminal);
Tree* Tree_new_empty();
void TreeNode_free(TreeNode *node);
void Tree_free(Tree *tree);
/*
Pre-functions for adding children
*/
void Tree_addLeftChild(TreeNode *parent, BOOL isTerminal, char *label, char *terminal);
void Tree_addCenterChild(TreeNode *parent, BOOL isTerminal, char *label, char *terminal);
void Tree_addRightChild(TreeNode *parent, BOOL isTerminal, char *label, char *terminal);
void Tree_addLeftSubTree(TreeNode *parent, Tree *tree);
void Tree_addCenterSubTree(TreeNode *parent, Tree *tree);
void Tree_addRightSubTree(TreeNode *parent, Tree *tree);
/*
Actual functions for adding children
*/
void Tree_addChild(TreeNode *parent, BOOL isTerminal, char *label, char *terminal);
void Tree_addChildNode(TreeNode *parent, TreeNode *node);
void Tree_addSubTree(TreeNode *parent, Tree *tree);
/*
Pre-functions for printing the tree in postorder
*/
void Tree_printFromNode(TreeNode *node, int level);
/*
Printing the tree in postorder
*/
void Tree_print(Tree *tree);
#endif