-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMexprTree.h
More file actions
70 lines (53 loc) · 1.88 KB
/
MexprTree.h
File metadata and controls
70 lines (53 loc) · 1.88 KB
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
#ifndef __MEXPR_TREE__
#define __MEXPR_TREE__
#include <stdbool.h>
#include <stdint.h>
#include "MexprcppEnums.h"
class Dtype;
class MexprNode {
private:
protected:
MexprNode();
public:
virtual ~MexprNode();
MexprNode *parent;
MexprNode *left;
MexprNode *right;
MexprNode *lst_left;
MexprNode *lst_right;
virtual MexprNode * clone() = 0;
virtual mexprcpp_dtypes_t ResultStorageType(mexprcpp_dtypes_t did1, mexprcpp_dtypes_t did2) = 0;
virtual Dtype* compute(Dtype *dtype1, Dtype *dtype2) = 0;
};
typedef struct lex_data_ lex_data_t;
class MexprTree {
private:
mexprcpp_dtypes_t validate_internal (MexprNode *root);
Dtype *evaluate_internal(MexprNode *root);
void destory_internal(MexprNode* root);
void NodeRemoveFromList(MexprNode* node);
void CloneNodesRecursively (MexprNode *src_node, MexprNode *new_node, int child);
void CreateOperandList ();
void CreateOperandList (MexprNode *node);
protected:
public:
MexprNode *root;
MexprNode *lst_head; /// will discuss in next lecture video !
MexprTree();
virtual ~MexprTree();
MexprTree(lex_data_t **postfix_lex_data_array, int size); // constructor
static void InorderPrint (MexprTree *tree);
bool validate (MexprNode *root);
Dtype *evaluate(MexprNode *root);
void destroy();
void destroy(MexprNode *root);
bool IsLoneVariableOperandNode();
bool concatenate (MexprNode *leaf_node, MexprTree *child_tree);
MexprTree *clone(MexprNode *root);
};
#define MexprTree_Iterator_Operands_Begin(tree_ptr, node_ptr) \
{ MexprNode *_next_node = NULL; \
for (node_ptr = tree_ptr->lst_head; node_ptr; node_ptr = _next_node){ \
_next_node = node_ptr->lst_right;
#define MexprTree_Iterator_Operands_End }}
#endif