This repository has been archived by the owner on Dec 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cool-tree.h
891 lines (761 loc) · 17.9 KB
/
cool-tree.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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
#ifndef COOL_TREE_H
#define COOL_TREE_H
//////////////////////////////////////////////////////////
//
// file: cool-tree.h
//
// This file defines classes for each phylum and constructor
//
//////////////////////////////////////////////////////////
#include "tree.h"
#include "cool-tree.handcode.h"
// define the class for phylum
// define simple phylum - Program
typedef class Program_class *Program;
class Program_class : public tree_node {
public:
tree_node *copy() { return copy_Program(); }
virtual Program copy_Program() = 0;
#ifdef Program_EXTRAS
Program_EXTRAS
#endif
};
// define simple phylum - Class_
typedef class Class__class *Class_;
class Class__class : public tree_node {
public:
tree_node *copy() { return copy_Class_(); }
virtual Class_ copy_Class_() = 0;
virtual Symbol getName() = 0;
virtual Features getFeaturs() = 0;
virtual void traverse() = 0;
#ifdef Class__EXTRAS
Class__EXTRAS
#endif
};
// define simple phylum - Feature
typedef class Feature_class *Feature;
class Feature_class : public tree_node {
public:
tree_node *copy() { return copy_Feature(); }
virtual Feature copy_Feature() = 0;
virtual Symbol getName() = 0;
virtual Symbol getType() = 0;
virtual void traverse() = 0;
#ifdef Feature_EXTRAS
Feature_EXTRAS
#endif
};
// define simple phylum - Formal
typedef class Formal_class *Formal;
class Formal_class : public tree_node {
public:
tree_node *copy() { return copy_Formal(); }
virtual Formal copy_Formal() = 0;
virtual Symbol getName() = 0;
virtual Symbol get_type() = 0;
#ifdef Formal_EXTRAS
Formal_EXTRAS
#endif
};
// define simple phylum - Expression
typedef class Expression_class *Expression;
class Expression_class : public tree_node {
public:
tree_node *copy() { return copy_Expression(); }
virtual Expression copy_Expression() = 0;
virtual void traverse() = 0;
#ifdef Expression_EXTRAS
Expression_EXTRAS
#endif
};
// define simple phylum - Case
typedef class Case_class *Case;
class Case_class : public tree_node {
public:
tree_node *copy() { return copy_Case(); }
virtual Case copy_Case() = 0;
virtual Symbol getIdentifierName() = 0;
virtual Symbol getIdentifierType() = 0;
virtual Symbol getReturnedExpressionType() = 0;
virtual void traverse() = 0;
#ifdef Case_EXTRAS
Case_EXTRAS
#endif
};
// define the class for phylum - LIST
// define list phlyum - Classes
typedef list_node<Class_> Classes_class;
typedef Classes_class *Classes;
// define list phlyum - Features
typedef list_node<Feature> Features_class;
typedef Features_class *Features;
// define list phlyum - Formals
typedef list_node<Formal> Formals_class;
typedef Formals_class *Formals;
// define list phlyum - Expressions
typedef list_node<Expression> Expressions_class;
typedef Expressions_class *Expressions;
// define list phlyum - Cases
typedef list_node<Case> Cases_class;
typedef Cases_class *Cases;
// define the class for constructors
// define constructor - program
class program_class : public Program_class {
protected:
Classes classes;
public:
program_class(Classes a1) {
classes = a1;
}
Program copy_Program();
void dump(ostream& stream, int n);
#ifdef Program_SHARED_EXTRAS
Program_SHARED_EXTRAS
#endif
#ifdef program_EXTRAS
program_EXTRAS
#endif
};
// define constructor - class_
class class__class : public Class__class {
protected:
Symbol name;
Symbol parent;
Features features;
Symbol filename;
public:
class__class(Symbol a1, Symbol a2, Features a3, Symbol a4) {
name = a1;
parent = a2;
features = a3;
filename = a4;
}
Class_ copy_Class_();
void dump(ostream& stream, int n);
virtual Symbol getName() {return name;}
virtual Features getFeaturs() {return features;}
virtual void traverse();
#ifdef Class__SHARED_EXTRAS
Class__SHARED_EXTRAS
#endif
#ifdef class__EXTRAS
class__EXTRAS
#endif
};
// define constructor - method
class method_class : public Feature_class {
protected:
Symbol name;
Formals formals;
Symbol return_type;
Expression expr;
public:
method_class(Symbol a1, Formals a2, Symbol a3, Expression a4) {
name = a1;
formals = a2;
return_type = a3;
expr = a4;
}
Feature copy_Feature();
void dump(ostream& stream, int n);
virtual Symbol getName() {return name;}
virtual Symbol getType() {return return_type;}
virtual Formals getFormals() {return formals;}
virtual void traverse();
#ifdef Feature_SHARED_EXTRAS
Feature_SHARED_EXTRAS
#endif
#ifdef method_EXTRAS
method_EXTRAS
#endif
};
// define constructor - attr
class attr_class : public Feature_class {
protected:
Symbol name;
Symbol type_decl;
Expression init;
public:
attr_class(Symbol a1, Symbol a2, Expression a3) {
name = a1;
type_decl = a2;
init = a3;
}
Feature copy_Feature();
void dump(ostream& stream, int n);
virtual Symbol getName() {return name;}
virtual void traverse();
virtual Symbol getType() {return type_decl;}
#ifdef Feature_SHARED_EXTRAS
Feature_SHARED_EXTRAS
#endif
#ifdef attr_EXTRAS
attr_EXTRAS
#endif
};
// define constructor - formal
class formal_class : public Formal_class {
protected:
Symbol name;
Symbol type_decl;
public:
formal_class(Symbol a1, Symbol a2) {
name = a1;
type_decl = a2;
}
Formal copy_Formal();
virtual Symbol getName() {return name;}
virtual Symbol get_type() {return type_decl;}
void dump(ostream& stream, int n);
#ifdef Formal_SHARED_EXTRAS
Formal_SHARED_EXTRAS
#endif
#ifdef formal_EXTRAS
formal_EXTRAS
#endif
};
// define constructor - branch
class branch_class : public Case_class {
protected:
Symbol name;
Symbol type_decl;
Expression expr;
public:
virtual void traverse();
branch_class(Symbol a1, Symbol a2, Expression a3) {
name = a1;
type_decl = a2;
expr = a3;
}
Case copy_Case();
virtual Symbol getIdentifierName() {return name;}
virtual Symbol getIdentifierType() {return type_decl;}
virtual Symbol getReturnedExpressionType() {return expr->get_type();}
void dump(ostream& stream, int n);
#ifdef Case_SHARED_EXTRAS
Case_SHARED_EXTRAS
#endif
#ifdef branch_EXTRAS
branch_EXTRAS
#endif
};
// define constructor - assign
class assign_class : public Expression_class {
protected:
Symbol name;
Expression expr;
public:
assign_class(Symbol a1, Expression a2) {
name = a1;
expr = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef assign_EXTRAS
assign_EXTRAS
#endif
};
// define constructor - static_dispatch
class static_dispatch_class : public Expression_class {
protected:
Expression expr;
Symbol type_name;
Symbol name;
Expressions actual;
public:
static_dispatch_class(Expression a1, Symbol a2, Symbol a3, Expressions a4) {
expr = a1;
type_name = a2;
name = a3;
actual = a4;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef static_dispatch_EXTRAS
static_dispatch_EXTRAS
#endif
};
// define constructor - dispatch
class dispatch_class : public Expression_class {
protected:
Expression expr;
Symbol name;
Expressions actual;
public:
dispatch_class(Expression a1, Symbol a2, Expressions a3) {
expr = a1;
name = a2;
actual = a3;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse() ;
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef dispatch_EXTRAS
dispatch_EXTRAS
#endif
};
// define constructor - cond
class cond_class : public Expression_class {
protected:
Expression pred;
Expression then_exp;
Expression else_exp;
public:
cond_class(Expression a1, Expression a2, Expression a3) {
pred = a1;
then_exp = a2;
else_exp = a3;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse() ;
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef cond_EXTRAS
cond_EXTRAS
#endif
};
// define constructor - loop
class loop_class : public Expression_class {
protected:
Expression pred;
Expression body;
public:
loop_class(Expression a1, Expression a2) {
pred = a1;
body = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef loop_EXTRAS
loop_EXTRAS
#endif
};
// define constructor - typcase
class typcase_class : public Expression_class {
protected:
Expression expr;
Cases cases;
public:
typcase_class(Expression a1, Cases a2) {
expr = a1;
cases = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse() ;
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef typcase_EXTRAS
typcase_EXTRAS
#endif
};
// define constructor - block
class block_class : public Expression_class {
protected:
Expressions body;
public:
block_class(Expressions a1) {
body = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef block_EXTRAS
block_EXTRAS
#endif
};
// define constructor - let
class let_class : public Expression_class {
protected:
Symbol identifier;
Symbol type_decl;
Expression init;
Expression body;
public:
let_class(Symbol a1, Symbol a2, Expression a3, Expression a4) {
identifier = a1;
type_decl = a2;
init = a3;
body = a4;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual Symbol getIdentifierName() {return identifier;}
virtual Symbol getIdentifierType() {return type_decl;}
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef let_EXTRAS
let_EXTRAS
#endif
};
// define constructor - plus
class plus_class : public Expression_class {
protected:
Expression e1;
Expression e2;
public:
plus_class(Expression a1, Expression a2) {
e1 = a1;
e2 = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef plus_EXTRAS
plus_EXTRAS
#endif
};
// define constructor - sub
class sub_class : public Expression_class {
protected:
Expression e1;
Expression e2;
public:
sub_class(Expression a1, Expression a2) {
e1 = a1;
e2 = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef sub_EXTRAS
sub_EXTRAS
#endif
};
// define constructor - mul
class mul_class : public Expression_class {
protected:
Expression e1;
Expression e2;
public:
mul_class(Expression a1, Expression a2) {
e1 = a1;
e2 = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef mul_EXTRAS
mul_EXTRAS
#endif
};
// define constructor - divide
class divide_class : public Expression_class {
protected:
Expression e1;
Expression e2;
public:
divide_class(Expression a1, Expression a2) {
e1 = a1;
e2 = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef divide_EXTRAS
divide_EXTRAS
#endif
};
// define constructor - neg
class neg_class : public Expression_class {
protected:
Expression e1;
public:
neg_class(Expression a1) {
e1 = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef neg_EXTRAS
neg_EXTRAS
#endif
};
// define constructor - lt
class lt_class : public Expression_class {
protected:
Expression e1;
Expression e2;
public:
lt_class(Expression a1, Expression a2) {
e1 = a1;
e2 = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef lt_EXTRAS
lt_EXTRAS
#endif
};
// define constructor - eq
class eq_class : public Expression_class {
protected:
Expression e1;
Expression e2;
public:
eq_class(Expression a1, Expression a2) {
e1 = a1;
e2 = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef eq_EXTRAS
eq_EXTRAS
#endif
};
// define constructor - leq
class leq_class : public Expression_class {
protected:
Expression e1;
Expression e2;
public:
leq_class(Expression a1, Expression a2) {
e1 = a1;
e2 = a2;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef leq_EXTRAS
leq_EXTRAS
#endif
};
// define constructor - comp
class comp_class : public Expression_class {
protected:
Expression e1;
public:
comp_class(Expression a1) {
e1 = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef comp_EXTRAS
comp_EXTRAS
#endif
};
// define constructor - int_const
class int_const_class : public Expression_class {
protected:
Symbol token;
public:
int_const_class(Symbol a1) {
token = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef int_const_EXTRAS
int_const_EXTRAS
#endif
};
// define constructor - bool_const
class bool_const_class : public Expression_class {
protected:
Boolean val;
public:
bool_const_class(Boolean a1) {
val = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef bool_const_EXTRAS
bool_const_EXTRAS
#endif
};
// define constructor - string_const
class string_const_class : public Expression_class {
protected:
Symbol token;
public:
string_const_class(Symbol a1) {
token = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef string_const_EXTRAS
string_const_EXTRAS
#endif
};
// define constructor - new_
class new__class : public Expression_class {
protected:
Symbol type_name;
public:
new__class(Symbol a1) {
type_name = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse() ;
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef new__EXTRAS
new__EXTRAS
#endif
};
// define constructor - isvoid
class isvoid_class : public Expression_class {
protected:
Expression e1;
public:
isvoid_class(Expression a1) {
e1 = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef isvoid_EXTRAS
isvoid_EXTRAS
#endif
};
// define constructor - no_expr
class no_expr_class : public Expression_class {
protected:
public:
no_expr_class() {
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef no_expr_EXTRAS
no_expr_EXTRAS
#endif
};
// define constructor - object
class object_class : public Expression_class {
protected:
Symbol name;
public:
object_class(Symbol a1) {
name = a1;
}
Expression copy_Expression();
void dump(ostream& stream, int n);
virtual void traverse();
#ifdef Expression_SHARED_EXTRAS
Expression_SHARED_EXTRAS
#endif
#ifdef object_EXTRAS
object_EXTRAS
#endif
};
// define the prototypes of the interface
Classes nil_Classes();
Classes single_Classes(Class_);
Classes append_Classes(Classes, Classes);
Features nil_Features();
Features single_Features(Feature);
Features append_Features(Features, Features);
Formals nil_Formals();
Formals single_Formals(Formal);
Formals append_Formals(Formals, Formals);
Expressions nil_Expressions();
Expressions single_Expressions(Expression);
Expressions append_Expressions(Expressions, Expressions);
Cases nil_Cases();
Cases single_Cases(Case);
Cases append_Cases(Cases, Cases);
Program program(Classes);
Class_ class_(Symbol, Symbol, Features, Symbol);
Feature method(Symbol, Formals, Symbol, Expression);
Feature attr(Symbol, Symbol, Expression);
Formal formal(Symbol, Symbol);
Case branch(Symbol, Symbol, Expression);
Expression assign(Symbol, Expression);
Expression static_dispatch(Expression, Symbol, Symbol, Expressions);
Expression dispatch(Expression, Symbol, Expressions);
Expression cond(Expression, Expression, Expression);
Expression loop(Expression, Expression);
Expression typcase(Expression, Cases);
Expression block(Expressions);
Expression let(Symbol, Symbol, Expression, Expression);
Expression plus(Expression, Expression);
Expression sub(Expression, Expression);
Expression mul(Expression, Expression);
Expression divide(Expression, Expression);
Expression neg(Expression);
Expression lt(Expression, Expression);
Expression eq(Expression, Expression);
Expression leq(Expression, Expression);
Expression comp(Expression);
Expression int_const(Symbol);
Expression bool_const(Boolean);
Expression string_const(Symbol);
Expression new_(Symbol);
Expression isvoid(Expression);
Expression no_expr();
Expression object(Symbol);
#endif