-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolExpr.h
More file actions
125 lines (95 loc) · 2.92 KB
/
BoolExpr.h
File metadata and controls
125 lines (95 loc) · 2.92 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
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
#ifndef BOOLEXPR_H
#define BOOLEXPR_H
#include <string>
#include "NumExpr.h"
using namespace std;
class Visitor;
//la classe BoolExpr è costituita da 3 sottoclassi
//creo la classe virtuale genitore e poi le tre classi figli che erediteranno dal genitore
//classe virtuale
class BoolExpr {
public:
virtual ~BoolExpr() {};
//metodo virutale per effettuare la visita dell'albero
virtual int64_t accept(Visitor* v) = 0;
};
//I classe figlio
class RelOp : public BoolExpr {
public:
enum OpCode_RelOp {LT, GT, EQ};
RelOp(OpCode_RelOp op, NumExpr* first, NumExpr* second) : _op{ op }, _first{ first }, _second{ second } {};
~RelOp() = default;
RelOp(const RelOp& other) = default;
RelOp& operator=(const RelOp& other) = default;
//getters
OpCode_RelOp get_op()const {
return _op;
}
NumExpr* get_first()const {
return _first;
}
NumExpr* get_second()const {
return _second;
}
static OpCode_RelOp stringToOpCode_Operator(string s) {
if (s == "LT") return LT;
else if (s == "GT") return GT;
else if (s == "EQ") return EQ;
}
//metodo concreto per effettuare la visita dell'albero
int64_t accept(Visitor* v) override;
private:
OpCode_RelOp _op;
NumExpr* _first;
NumExpr* _second;
};
//II classe figlio
class BoolConst :public BoolExpr {
public:
enum OpCode_BoolConst { TRUE, FALSE};
BoolConst(OpCode_BoolConst op) : _op{ op } {};
~BoolConst() = default;
BoolConst(const BoolConst& other) = default;
BoolConst& operator=(const BoolConst& other) = default;
OpCode_BoolConst get_lop()const {
return _op;
}
static OpCode_BoolConst stringToOpCode_Operator(std::string s) {
if (s == "TRUE") return TRUE;
else if (s == "FALSE") return FALSE;
}
//metodo concreto per la visita dell'albero
int64_t accept(Visitor* v) override;
private:
OpCode_BoolConst _op;
};
//III classe figlio
class BoolOp : public BoolExpr {
public:
enum OpCode_BoolOp {AND, OR, NOT};
BoolOp(OpCode_BoolOp op, BoolExpr* first, BoolExpr* second) : _op{ op }, _first{ first }, _second{ second } {};
~BoolOp() = default;
BoolOp(const BoolOp& other) = default;
BoolOp& operator=(const BoolOp& other) = default;
OpCode_BoolOp get_op()const {
return _op;
}
BoolExpr* get_first()const {
return _first;
}
BoolExpr* get_second()const {
return _second;
}
static OpCode_BoolOp stringToOpCode_Operator(std::string s) {
if (s == "AND") return AND;
else if (s == "OR") return OR;
else if (s == "NOT") return NOT;
}
//metodo concreto per la visita dell'albero
int64_t accept(Visitor* v) override;
private:
OpCode_BoolOp _op;
BoolExpr* _first;
BoolExpr* _second;
};
#endif