-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodes.hpp
80 lines (60 loc) · 1.49 KB
/
nodes.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
#include"lex.hpp"
class AstNode {
public:
virtual ~AstNode() = default;
virtual std::string getLabel() const = 0;
};
class OrAstNode : public AstNode {
public:
std::shared_ptr<AstNode> left;
std::shared_ptr<AstNode> right;
OrAstNode(std::shared_ptr<AstNode> left, std::shared_ptr<AstNode> right) {
this->left = left;
this->right = right;
}
std::string getLabel() const override {
return "|";
}
};
class SeqAstNode : public AstNode {
public:
std::shared_ptr<AstNode> left;
std::shared_ptr<AstNode> right;
SeqAstNode(std::shared_ptr<AstNode> left, std::shared_ptr<AstNode> right){
this->left = left;
this->right = right;
}
std::string getLabel() const override {
return "&";
}
};
class StarAstNode : public AstNode {
public:
std::shared_ptr<AstNode> left;
explicit StarAstNode(std::shared_ptr<AstNode> left) {
this->left = left;
}
std::string getLabel() const override {
return "*";
}
};
class PlusAstNode : public AstNode {
public:
std::shared_ptr<AstNode> left ;
explicit PlusAstNode(std::shared_ptr<AstNode> left) {
this->left = left ;
}
std::string getLabel() const override {
return "+";
}
};
class LiteralCharacterAstNode : public AstNode {
public:
char ch;
explicit LiteralCharacterAstNode(char ch) {
this->ch = ch;
}
std::string getLabel() const override {
return std::string(1, ch);
}
};