-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatement.h
More file actions
157 lines (121 loc) · 3.43 KB
/
Statement.h
File metadata and controls
157 lines (121 loc) · 3.43 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
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
#ifndef STATEMENT_H
#define STATEMENT_H
#include "NumExpr.h"
#include "BoolExpr.h"
//#include "Block.h"
using namespace std;
//calsse Block implementata da un'altra parte
class Block;
//classe visitor implementata da un'altra parte
class Visitor;
// la classe Statement è costituita da cinque sottoclassi
//creo la classe virtuale genitore e poi le cinque classi figli che erediteranno dal genitore
//classe virtuale
class Statement {
public:
virtual ~Statement() {};
//metodo virtuale per visitare l'albero
virtual void accept(Visitor* v) = 0;
};
//I classe figlio
class PrintStmt : public Statement {
public:
PrintStmt(NumExpr* element) : _element{ element } {};
~PrintStmt() = default;
PrintStmt(const PrintStmt& other) = default;
PrintStmt& operator=(const PrintStmt& other) = default;
NumExpr* get_element()const {
return _element;
}
void accept(Visitor* v) override;
private:
NumExpr* _element;
};
//II classe figlio
class SetStmt : public Statement {
public:
SetStmt(Variable* first, NumExpr* second) : _first{ first }, _second{ second } {};
~SetStmt() = default;
SetStmt(const SetStmt& other) = default;
SetStmt& operator=(const SetStmt& other) = default;
//getters
Variable* get_first()const {
return _first;
}
NumExpr* get_second()const {
return _second;
}
//setters
void set_first(Variable* first) {
_first = first;
}
void set_second(NumExpr* second) {
_second = second;
}
//metodo concreto per la visita
void accept(Visitor* v) override;
private:
Variable* _first;
NumExpr* _second;
};
//III classe figlio
class InputStmt : public Statement {
public:
InputStmt(Variable* element) : _element{ element } {};
~InputStmt() = default;
InputStmt(const InputStmt& other) = default;
InputStmt& operator=(const InputStmt& other) = default;
//getter
Variable* get_element()const {
return _element;
}
//metodo concreto per la visita
void accept(Visitor* v) override;
private:
Variable* _element;
};
//IV clsse figlio
class WhileStmt : public Statement {
public:
WhileStmt(BoolExpr* first, Block* second) : _first{ first }, _second{ second } {};
~WhileStmt() = default;
WhileStmt(const WhileStmt& other) = default;
WhileStmt& operator=(const WhileStmt& other) = default;
//getters
BoolExpr* get_first()const {
return _first;
}
Block* get_second()const {
return _second;
}
//metodo concreto per la visita
void accept(Visitor* v) override;
private:
BoolExpr* _first;
Block* _second;
};
//V classe figlio
class IfStmt : public Statement {
public:
IfStmt(BoolExpr* first, Block* second, Block* third) : _first{ first }, _second{ second }, _third{ third } {};
~IfStmt() = default;
IfStmt(const IfStmt& other) = default;
IfStmt& operator=(const IfStmt& other) = default;
//getters
BoolExpr* get_first() const {
return _first;
}
Block* get_second() const {
return _second;
}
Block* get_third() const {
return _third;
}
//metodo concreto per la visita
void accept(Visitor* v) override;
private:
BoolExpr* _first;
Block* _second;
Block* _third;
};
#endif