This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RE_RegularExpression.hpp
80 lines (72 loc) · 2.69 KB
/
RE_RegularExpression.hpp
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
/**
* @file RE_RegularExpression.hpp
* Definition of the regular expression class.
* @author Daniel Dreibrodt, Konstantin Steinmiller
*/
#ifndef REGULAREXPRESSION_H_
#define REGULAREXPRESSION_H_
#include <string>
#include "RE_TreeNode.hpp"
#include "FSA_FiniteStateAutomaton.hpp"
#include "RG_Grammar.h"
using namespace std;
/**
* @brief This class represents regular expressions.
*
* Regular expressions are stored in objects of this class. The underlying data structure
* is an expression tree. Operators are stored in nodes that have their operands as children.
* Literals are stored in the leafs of the expression tree.
*
* Valid operators are:
*
* <ul>
* <li><b>|</b> - boolean or - Either the preceding or the following operand have to occur</li>
* <li><b>.</b> - and/concatenation - The preceding element has to be followed by the next element.</li>
* <li><b>*</b> - star quantifier - The preceding element can occur zero or more times</li>
* <li><b>(</b> - opening parenthesis - Starts a group, used to express precedence</li>
* <li><b>)</b> - closing parenthesis - Closes a group, used to express precedence</li>
* </ul>
*
* Valid literals are all strings that do not contain spaces or operators.
*
* The empty literal is represented by <i><epsilon></i>.
* @author Daniel Dreibrodt, Konstantin Steinmiller
* @see RETreeNode
*/
class RegularExpression {
public:
RegularExpression(RETreeNode *p_tR);
RegularExpression(string regex);
virtual ~RegularExpression();
void setTreeRoot(RETreeNode *p_tR);
RETreeNode *getTreeRoot();
FiniteStateAutomaton *toFSA();
Grammar *toRG();
string toString();
/** String representation of the boolean or operator **/
static const string re_orOp;
/** String representation of the concatenation operator **/
static const string re_andOp;
/** String representation of the Kleene-star operator (preceding element occurs zero or more times) **/
static const string re_starOp;
/** String representation of the opening parenthesis **/
static const string re_lParen;
/** String representation of the closing parenthesis **/
static const string re_rParen;
/**
* Checks whether a given string is a valid operator in the
* regular expression syntax
* @author Daniel Dreibrodt, Konstantin Steinmiller
*/
static inline bool isOperator(string s) {
return s == RegularExpression::re_andOp
|| s == RegularExpression::re_orOp
|| s == RegularExpression::re_starOp
|| s == RegularExpression::re_lParen
|| s == RegularExpression::re_rParen;
}
private:
//Contains the root of the expression tree
RETreeNode *p_treeRoot;
};
#endif /* REGULAREXPRESSION_H_ */