-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbsyn.H
689 lines (583 loc) · 12.6 KB
/
Absyn.H
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#ifndef ABSYN_HEADER
#define ABSYN_HEADER
#include<string>
#include<vector>
//C++ Abstract Syntax Interface generated by the BNF Converter.
/******************** TypeDef Section ********************/
typedef int Integer;
typedef char Char;
typedef double Double;
typedef std::string String;
typedef std::string Ident;
typedef std::string Id;
/******************** Forward Declarations ********************/
class Program;
class Dfn;
class Dmem;
class Def;
class Arg;
class Stm;
class Exp;
class PDefs;
class DFun;
class DMember;
class DClass;
class ADecl;
class SExp;
class SInit;
class SMemInit;
class SReturn;
class SWhile;
class SIfElse;
class SException;
class SThrow;
class EInt;
class EDouble;
class EString;
class EId;
class EApp;
class SNewClass;
class SClassMember;
class SClassMemberVar;
class ETimes;
class EDiv;
class EPlus;
class EMinus;
class ELt;
class EGt;
class EEq;
class ENEq;
class EAss;
class ListDef;
class ListDfn;
class ListDmem;
class ListArg;
class ListStm;
class ListExp;
class ListId;
/******************** Visitor Interfaces ********************/
class Visitor
{
public:
virtual ~Visitor() {}
virtual void visitProgram(Program *p) = 0;
virtual void visitDfn(Dfn *p) = 0;
virtual void visitDmem(Dmem *p) = 0;
virtual void visitDef(Def *p) = 0;
virtual void visitArg(Arg *p) = 0;
virtual void visitStm(Stm *p) = 0;
virtual void visitExp(Exp *p) = 0;
virtual void visitPDefs(PDefs *p) = 0;
virtual void visitDFun(DFun *p) = 0;
virtual void visitDMember(DMember *p) = 0;
virtual void visitDClass(DClass *p) = 0;
virtual void visitADecl(ADecl *p) = 0;
virtual void visitSExp(SExp *p) = 0;
virtual void visitSInit(SInit *p) = 0;
virtual void visitSMemInit(SMemInit *p) = 0;
virtual void visitSReturn(SReturn *p) = 0;
virtual void visitSWhile(SWhile *p) = 0;
virtual void visitSIfElse(SIfElse *p) = 0;
virtual void visitSException(SException *p) = 0;
virtual void visitSThrow(SThrow *p) = 0;
virtual void visitEInt(EInt *p) = 0;
virtual void visitEDouble(EDouble *p) = 0;
virtual void visitEString(EString *p) = 0;
virtual void visitEId(EId *p) = 0;
virtual void visitEApp(EApp *p) = 0;
virtual void visitSNewClass(SNewClass *p) = 0;
virtual void visitSClassMember(SClassMember *p) = 0;
virtual void visitSClassMemberVar(SClassMemberVar *p) = 0;
virtual void visitETimes(ETimes *p) = 0;
virtual void visitEDiv(EDiv *p) = 0;
virtual void visitEPlus(EPlus *p) = 0;
virtual void visitEMinus(EMinus *p) = 0;
virtual void visitELt(ELt *p) = 0;
virtual void visitEGt(EGt *p) = 0;
virtual void visitEEq(EEq *p) = 0;
virtual void visitENEq(ENEq *p) = 0;
virtual void visitEAss(EAss *p) = 0;
virtual void visitListDef(ListDef *p) = 0;
virtual void visitListDfn(ListDfn *p) = 0;
virtual void visitListDmem(ListDmem *p) = 0;
virtual void visitListArg(ListArg *p) = 0;
virtual void visitListStm(ListStm *p) = 0;
virtual void visitListExp(ListExp *p) = 0;
virtual void visitListId(ListId *p) = 0;
virtual void visitInteger(Integer x) = 0;
virtual void visitChar(Char x) = 0;
virtual void visitDouble(Double x) = 0;
virtual void visitString(String x) = 0;
virtual void visitIdent(Ident x) = 0;
virtual void visitId(Id x) = 0;
};
class Visitable
{
public:
virtual ~Visitable() {}
virtual void accept(Visitor *v) = 0;
};
/******************** Abstract Syntax Classes ********************/
class Program : public Visitable
{
public:
virtual Program *clone() const = 0;
};
class Dfn : public Visitable
{
public:
virtual Dfn *clone() const = 0;
};
class Dmem : public Visitable
{
public:
virtual Dmem *clone() const = 0;
};
class Def : public Visitable
{
public:
virtual Def *clone() const = 0;
};
class Arg : public Visitable
{
public:
virtual Arg *clone() const = 0;
};
class Stm : public Visitable
{
public:
virtual Stm *clone() const = 0;
};
class Exp : public Visitable
{
public:
virtual Exp *clone() const = 0;
};
class PDefs : public Program
{
public:
ListDef *listdef_;
PDefs(const PDefs &);
PDefs &operator=(const PDefs &);
PDefs(ListDef *p1);
~PDefs();
virtual void accept(Visitor *v);
virtual PDefs *clone() const;
void swap(PDefs &);
};
class DFun : public Dfn
{
public:
Id id_;
ListArg *listarg_;
ListStm *liststm_;
DFun(const DFun &);
DFun &operator=(const DFun &);
DFun(Id p1, ListArg *p2, ListStm *p3);
~DFun();
virtual void accept(Visitor *v);
virtual DFun *clone() const;
void swap(DFun &);
};
class DMember : public Dmem
{
public:
Id id_;
DMember(const DMember &);
DMember &operator=(const DMember &);
DMember(Id p1);
~DMember();
virtual void accept(Visitor *v);
virtual DMember *clone() const;
void swap(DMember &);
};
class DClass : public Def
{
public:
Id id_1;
Id id_2;
ListDmem *listdmem_;
ListDfn *listdfn_;
DClass(const DClass &);
DClass &operator=(const DClass &);
DClass(Id p1, Id p2, ListDmem *p3, ListDfn *p4);
~DClass();
virtual void accept(Visitor *v);
virtual DClass *clone() const;
void swap(DClass &);
};
class ADecl : public Arg
{
public:
Id id_;
ADecl(const ADecl &);
ADecl &operator=(const ADecl &);
ADecl(Id p1);
~ADecl();
virtual void accept(Visitor *v);
virtual ADecl *clone() const;
void swap(ADecl &);
};
class SExp : public Stm
{
public:
Exp *exp_;
SExp(const SExp &);
SExp &operator=(const SExp &);
SExp(Exp *p1);
~SExp();
virtual void accept(Visitor *v);
virtual SExp *clone() const;
void swap(SExp &);
};
class SInit : public Stm
{
public:
Id id_;
Exp *exp_;
SInit(const SInit &);
SInit &operator=(const SInit &);
SInit(Id p1, Exp *p2);
~SInit();
virtual void accept(Visitor *v);
virtual SInit *clone() const;
void swap(SInit &);
};
class SMemInit : public Stm
{
public:
Id id_1;
Id id_2;
Exp *exp_;
SMemInit(const SMemInit &);
SMemInit &operator=(const SMemInit &);
SMemInit(Id p1, Id p2, Exp *p3);
~SMemInit();
virtual void accept(Visitor *v);
virtual SMemInit *clone() const;
void swap(SMemInit &);
};
class SReturn : public Stm
{
public:
Exp *exp_;
SReturn(const SReturn &);
SReturn &operator=(const SReturn &);
SReturn(Exp *p1);
~SReturn();
virtual void accept(Visitor *v);
virtual SReturn *clone() const;
void swap(SReturn &);
};
class SWhile : public Stm
{
public:
Exp *exp_;
ListStm *liststm_;
SWhile(const SWhile &);
SWhile &operator=(const SWhile &);
SWhile(Exp *p1, ListStm *p2);
~SWhile();
virtual void accept(Visitor *v);
virtual SWhile *clone() const;
void swap(SWhile &);
};
class SIfElse : public Stm
{
public:
Exp *exp_;
ListStm *liststm_1;
ListStm *liststm_2;
SIfElse(const SIfElse &);
SIfElse &operator=(const SIfElse &);
SIfElse(Exp *p1, ListStm *p2, ListStm *p3);
~SIfElse();
virtual void accept(Visitor *v);
virtual SIfElse *clone() const;
void swap(SIfElse &);
};
class SException : public Stm
{
public:
ListStm *liststm_1;
ListStm *liststm_2;
SException(const SException &);
SException &operator=(const SException &);
SException(ListStm *p1, ListStm *p2);
~SException();
virtual void accept(Visitor *v);
virtual SException *clone() const;
void swap(SException &);
};
class SThrow : public Stm
{
public:
String string_;
SThrow(const SThrow &);
SThrow &operator=(const SThrow &);
SThrow(String p1);
~SThrow();
virtual void accept(Visitor *v);
virtual SThrow *clone() const;
void swap(SThrow &);
};
class EInt : public Exp
{
public:
Integer integer_;
EInt(const EInt &);
EInt &operator=(const EInt &);
EInt(Integer p1);
~EInt();
virtual void accept(Visitor *v);
virtual EInt *clone() const;
void swap(EInt &);
};
class EDouble : public Exp
{
public:
Double double_;
EDouble(const EDouble &);
EDouble &operator=(const EDouble &);
EDouble(Double p1);
~EDouble();
virtual void accept(Visitor *v);
virtual EDouble *clone() const;
void swap(EDouble &);
};
class EString : public Exp
{
public:
String string_;
EString(const EString &);
EString &operator=(const EString &);
EString(String p1);
~EString();
virtual void accept(Visitor *v);
virtual EString *clone() const;
void swap(EString &);
};
class EId : public Exp
{
public:
Id id_;
EId(const EId &);
EId &operator=(const EId &);
EId(Id p1);
~EId();
virtual void accept(Visitor *v);
virtual EId *clone() const;
void swap(EId &);
};
class EApp : public Exp
{
public:
Id id_;
ListExp *listexp_;
EApp(const EApp &);
EApp &operator=(const EApp &);
EApp(Id p1, ListExp *p2);
~EApp();
virtual void accept(Visitor *v);
virtual EApp *clone() const;
void swap(EApp &);
};
class SNewClass : public Exp
{
public:
Id id_;
SNewClass(const SNewClass &);
SNewClass &operator=(const SNewClass &);
SNewClass(Id p1);
~SNewClass();
virtual void accept(Visitor *v);
virtual SNewClass *clone() const;
void swap(SNewClass &);
};
class SClassMember : public Exp
{
public:
Id id_1;
Id id_2;
ListExp *listexp_;
SClassMember(const SClassMember &);
SClassMember &operator=(const SClassMember &);
SClassMember(Id p1, Id p2, ListExp *p3);
~SClassMember();
virtual void accept(Visitor *v);
virtual SClassMember *clone() const;
void swap(SClassMember &);
};
class SClassMemberVar : public Exp
{
public:
Id id_1;
Id id_2;
SClassMemberVar(const SClassMemberVar &);
SClassMemberVar &operator=(const SClassMemberVar &);
SClassMemberVar(Id p1, Id p2);
~SClassMemberVar();
virtual void accept(Visitor *v);
virtual SClassMemberVar *clone() const;
void swap(SClassMemberVar &);
};
class ETimes : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
ETimes(const ETimes &);
ETimes &operator=(const ETimes &);
ETimes(Exp *p1, Exp *p2);
~ETimes();
virtual void accept(Visitor *v);
virtual ETimes *clone() const;
void swap(ETimes &);
};
class EDiv : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
EDiv(const EDiv &);
EDiv &operator=(const EDiv &);
EDiv(Exp *p1, Exp *p2);
~EDiv();
virtual void accept(Visitor *v);
virtual EDiv *clone() const;
void swap(EDiv &);
};
class EPlus : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
EPlus(const EPlus &);
EPlus &operator=(const EPlus &);
EPlus(Exp *p1, Exp *p2);
~EPlus();
virtual void accept(Visitor *v);
virtual EPlus *clone() const;
void swap(EPlus &);
};
class EMinus : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
EMinus(const EMinus &);
EMinus &operator=(const EMinus &);
EMinus(Exp *p1, Exp *p2);
~EMinus();
virtual void accept(Visitor *v);
virtual EMinus *clone() const;
void swap(EMinus &);
};
class ELt : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
ELt(const ELt &);
ELt &operator=(const ELt &);
ELt(Exp *p1, Exp *p2);
~ELt();
virtual void accept(Visitor *v);
virtual ELt *clone() const;
void swap(ELt &);
};
class EGt : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
EGt(const EGt &);
EGt &operator=(const EGt &);
EGt(Exp *p1, Exp *p2);
~EGt();
virtual void accept(Visitor *v);
virtual EGt *clone() const;
void swap(EGt &);
};
class EEq : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
EEq(const EEq &);
EEq &operator=(const EEq &);
EEq(Exp *p1, Exp *p2);
~EEq();
virtual void accept(Visitor *v);
virtual EEq *clone() const;
void swap(EEq &);
};
class ENEq : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
ENEq(const ENEq &);
ENEq &operator=(const ENEq &);
ENEq(Exp *p1, Exp *p2);
~ENEq();
virtual void accept(Visitor *v);
virtual ENEq *clone() const;
void swap(ENEq &);
};
class EAss : public Exp
{
public:
Exp *exp_1;
Exp *exp_2;
EAss(const EAss &);
EAss &operator=(const EAss &);
EAss(Exp *p1, Exp *p2);
~EAss();
virtual void accept(Visitor *v);
virtual EAss *clone() const;
void swap(EAss &);
};
class ListDef : public Visitable, public std::vector<Def*>
{
public:
virtual void accept(Visitor *v);
virtual ListDef *clone() const;
};
class ListDfn : public Visitable, public std::vector<Dfn*>
{
public:
virtual void accept(Visitor *v);
virtual ListDfn *clone() const;
};
class ListDmem : public Visitable, public std::vector<Dmem*>
{
public:
virtual void accept(Visitor *v);
virtual ListDmem *clone() const;
};
class ListArg : public Visitable, public std::vector<Arg*>
{
public:
virtual void accept(Visitor *v);
virtual ListArg *clone() const;
};
class ListStm : public Visitable, public std::vector<Stm*>
{
public:
virtual void accept(Visitor *v);
virtual ListStm *clone() const;
};
class ListExp : public Visitable, public std::vector<Exp*>
{
public:
virtual void accept(Visitor *v);
virtual ListExp *clone() const;
};
class ListId : public Visitable, public std::vector<Id>
{
public:
virtual void accept(Visitor *v);
virtual ListId *clone() const;
};
#endif