-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregex.h
192 lines (127 loc) · 3.76 KB
/
regex.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* regex.h
*
* Created on 14th March 2010 to organize code better.
*
*/
#define EPSILON -1 // empty string
#define NULLSET -2 // null set
#include "alphabet.h"
using namespace std;
class regexNode{
public:
//Virtual functions call the function to the corresponding object, even though the pointer is declared for the class higher in the hierarchy
//Test functions
virtual bool isLeaf();
virtual bool isStar();
virtual bool isUnion();
virtual bool isConcat() ;
virtual bool isUnionTree();//Checks the tree starting from this node is UnionTree. UnionTree is one in which if there is any operation each is a Union
virtual bool isNULL();
virtual bool isEmpty();
//Getters and Setters for Children and others
virtual bool setLeftChild(regexNode* );
virtual regexNode* getLeftChild();
virtual bool setRightChild(regexNode*);
virtual regexNode* getRightChild();
virtual bool setChildren(regexNode*, regexNode*);
virtual char getSymbol();
virtual alphabet getLeaves() =0; //Returns the leaves of the tree in the form of a stringstream
//Display
virtual void display() =0;
virtual void type();
//Operators
virtual regexNode * simplify() = 0;
virtual regexNode * replicate() =0;
regexNode * operator + (regexNode& );
regexNode * operator ++ (int);//The int is used to indicate that the operator is postfix.
regexNode * operator - (regexNode& );
friend ostream& operator << (ostream& , regexNode* );
friend ostream& operator << (ostream& , regexNode& );
friend istream& operator >> (istream& , regexNode& );
//Delete functions
virtual ~regexNode();
//virtual void delTree()=0;
};
/*********************** Unary Regex Node **************************/
class unaryRegexNode: public regexNode{
protected:
regexNode* leftChild;
public:
bool setLeftChild(regexNode *);
regexNode * getLeftChild();
alphabet getLeaves();
void type();
virtual ~unaryRegexNode();
//void delTree();
};
/*********************** Binary Regex Node **************************/
class binaryRegexNode: public unaryRegexNode{
protected:
regexNode* rightChild;
public:
bool setRightChild(regexNode *) ;
regexNode * getRightChild();
bool setChildren(regexNode* , regexNode* );
alphabet getLeaves();
void type();
virtual ~binaryRegexNode();
};
/*********************** Leaf Node **************************/
class leafNode: public regexNode {
private:
char symbol;
public:
leafNode();
leafNode(char );
bool isLeaf();
bool isUnionTree();
char getSymbol();
alphabet getLeaves();
void display();
void type();
regexNode * simplify();
regexNode * replicate();
~leafNode();
};
/*********************** Star Node **************************/
class starNode: public unaryRegexNode{
public:
starNode();
starNode (regexNode *);
bool isStar();
void display();
void type();
regexNode * simplify();
regexNode * replicate();
~starNode();
};
/*********************** Union Node **************************/
class unionNode: public binaryRegexNode{
public:
unionNode();
unionNode( regexNode * , regexNode * );
bool isUnion();
bool isUnionTree();
void display();
void type();
regexNode * simplify();
regexNode * replicate();
~unionNode();
};
/*********************** Concatination Node **************************/
class concatNode: public binaryRegexNode{
public:
concatNode();
concatNode(regexNode * , regexNode * );
bool isConcat();
void display();
void type();
regexNode * simplify();
regexNode * replicate();
~concatNode();
};
//void operator << (ostream& s, regex& a);
ostream& operator << (ostream& , regexNode* );
ostream& operator << (ostream& , regexNode& );
istream& operator >> (istream& , regexNode& );