-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAST.hpp
397 lines (313 loc) · 11.9 KB
/
AST.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#ifndef AST_HPP_
#define AST_HPP_
#include <string>
#include <iostream>
#include "Visitor.hpp"
#include "boost/any.hpp"
#include <PQL/PQL.h>
namespace VerifyTAPN {
namespace TAPN {
class TimedArcPetriNet;
}
namespace AST {
class Visitable
{
public:
virtual void Accept(Visitor& visitor, boost::any& context) const = 0;
};
class Expression : public Visitable
{
public:
virtual ~Expression() { };
//virtual void Accept(Visitor& visitor, boost::any& context) const = 0;
virtual Expression* clone() const = 0;
};
class NotExpression : public Expression
{
public:
explicit NotExpression(Expression* expr) : expr(expr) { };
NotExpression(const NotExpression& other) : expr(other.expr->clone()) { };
NotExpression& operator=(const NotExpression& other)
{
if(&other != this){
delete expr;
expr = other.expr->clone();
}
return *this;
}
virtual ~NotExpression(){
if( expr ) delete expr;
};
virtual NotExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
const Expression& Child() const { return *expr; }
private:
Expression* expr;
};
class BoolExpression : public Expression
{
public:
explicit BoolExpression(bool value) : value(value) {};
virtual ~BoolExpression() { };
virtual BoolExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
bool GetValue() const { return value; };
private:
bool value;
};
class AtomicProposition : public Expression
{
public:
AtomicProposition(ArithmeticExpression* left, std::string op,ArithmeticExpression* right) : left(left), op(std::move(op)), right(right){};
AtomicProposition(const AtomicProposition& other) : left(other.left), op(other.op), right(other.right) { };
AtomicProposition& operator=(const AtomicProposition& other)
{
if(&other != this){
left = other.left;
op = other.op;
right = other.right;
}
return *this;
}
virtual ~AtomicProposition() { };
ArithmeticExpression& GetLeft() const {return *left;};
ArithmeticExpression& GetRight() const {return *right;};
std::string GetOperator() const {return op;};
virtual AtomicProposition* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
const std::string& Operator() const { return op; }
private:
ArithmeticExpression* left;
std::string op;
ArithmeticExpression* right;
};
class AndExpression : public Expression
{
public:
AndExpression(Expression* left, Expression* right) : left(left), right(right) { };
AndExpression(const AndExpression& other) : left(other.left->clone()), right(other.right->clone()) {};
AndExpression& operator=(const AndExpression& other)
{
if(&other != this){
delete left;
delete right;
left = other.left->clone();
right = other.right->clone();
}
return *this;
}
virtual ~AndExpression() {
if( left ) delete left;
if( right ) delete right;
}
virtual AndExpression* clone() const;
void Accept(Visitor& visitor, boost::any& context) const;
const Expression& Left() const { return *left; }
const Expression& Right() const { return *right; }
private:
Expression* left;
Expression* right;
};
class OrExpression : public Expression
{
public:
OrExpression(Expression* left, Expression* right) : left(left), right(right) { };
OrExpression(const OrExpression& other) : left(other.left->clone()), right(other.right->clone()) { };
OrExpression& operator=(const OrExpression& other)
{
if(&other != this){
delete left;
delete right;
left = other.left->clone();
right = other.right->clone();
}
return *this;
}
virtual ~OrExpression(){
if( left ) delete left;
if( right ) delete right;
};
virtual OrExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
const Expression& Left() const { return *left; }
const Expression& Right() const { return *right; }
private:
Expression* left;
Expression* right;
};
class ArithmeticExpression : public Visitable
{
public:
virtual ~ArithmeticExpression() { };
virtual ArithmeticExpression* clone() const = 0;
};
class OperationExpression : public ArithmeticExpression {
protected:
OperationExpression(ArithmeticExpression* left, ArithmeticExpression* right) : left(left), right(right) {
};
OperationExpression(const OperationExpression& other) : left(other.left), right(other.right) {
};
OperationExpression& operator=(const OperationExpression& other) {
if (&other != this) {
delete left;
left = other.left;
delete right;
right = other.right;
}
return *this;
}
virtual ~OperationExpression() {
};
public:
ArithmeticExpression& GetLeft() const {return *left;};
ArithmeticExpression& GetRight() const {return *right;};
protected:
ArithmeticExpression* left;
ArithmeticExpression* right;
};
class PlusExpression : public OperationExpression {
public:
PlusExpression(ArithmeticExpression* left, ArithmeticExpression* right)
: OperationExpression(left, right) {
};
PlusExpression(const PlusExpression& other)
: OperationExpression(other) {
};
PlusExpression& operator=(const PlusExpression& other) {
if (&other != this) {
left = other.left;
right = other.right;
}
return *this;
}
virtual ~PlusExpression() {
};
virtual PlusExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
};
class SubtractExpression : public OperationExpression {
public:
SubtractExpression(ArithmeticExpression* left, ArithmeticExpression* right)
: OperationExpression(left, right) {
};
SubtractExpression(const SubtractExpression& other)
: OperationExpression(other) {
};
SubtractExpression& operator=(const SubtractExpression& other) {
if (&other != this) {
left = other.left;
right = other.right;
}
return *this;
}
virtual ~SubtractExpression() {
};
virtual SubtractExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
};
class MinusExpression : public ArithmeticExpression {
public:
MinusExpression(ArithmeticExpression* value) : value(value) {
};
MinusExpression(const MinusExpression& other)
: value(other.value) {
};
MinusExpression& operator=(const MinusExpression& other) {
if (&other != this) {
value = other.value;
}
return *this;
}
ArithmeticExpression& GetValue() const { return *value;};
virtual ~MinusExpression() {
};
virtual MinusExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
private:
ArithmeticExpression* value;
};
class MultiplyExpression : public OperationExpression {
public:
MultiplyExpression(ArithmeticExpression* left, ArithmeticExpression* right)
: OperationExpression(left, right) {
};
MultiplyExpression(const MultiplyExpression& other)
: OperationExpression(other) {
};
MultiplyExpression& operator=(const MultiplyExpression& other) {
if (&other != this) {
left = other.left;
right = other.right;
}
return *this;
}
virtual ~MultiplyExpression() {
};
virtual MultiplyExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
};
class NumberExpression : public ArithmeticExpression {
public:
NumberExpression(int i) : value(i) {
}
NumberExpression(const NumberExpression& other) : value(other.value) {
};
NumberExpression& operator=(const NumberExpression& other) {
value = other.value;
return *this;
};
int GetValue() const {return value;};
virtual ~NumberExpression() {
};
virtual NumberExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
private:
int value;
};
class IdentifierExpression : public ArithmeticExpression {
public:
IdentifierExpression(int placeIndex) : place(placeIndex) {
}
IdentifierExpression(const IdentifierExpression& other) : place(other.place) {
};
IdentifierExpression& operator=(const IdentifierExpression& other) {
place = other.place;
return *this;
};
int GetPlace() const { return place;};
virtual ~IdentifierExpression() {
};
virtual IdentifierExpression* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
private:
int place;
};
enum Quantifier { EF, AG, EG, AF};
class Query : public Visitable
{
public:
Query(Quantifier quantifier, Expression* expr) : quantifier(quantifier), expr(expr) { };
Query(const Query& other) : quantifier(other.quantifier), expr(other.expr->clone()) { };
Query& operator=(const Query& other)
{
if(&other != this){
delete expr;
expr = other.expr->clone();
}
return *this;
}
virtual ~Query() {
if( expr ) delete expr;
}
virtual Query* clone() const;
virtual void Accept(Visitor& visitor, boost::any& context) const;
Quantifier GetQuantifier() const { return quantifier; }
const Expression& Child() const { return *expr; }
private:
Quantifier quantifier;
Expression* expr;
};
std::unique_ptr<Query> toAST(const unfoldtacpn::PQL::Condition_ptr& ptr, const TAPN::TimedArcPetriNet& tapn);
}
}
#endif /* AST_HPP_ */