-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParseTree.h
1009 lines (915 loc) · 23.4 KB
/
ParseTree.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
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef PARSETREE_H
#define PARSETREE_H
extern "C" {
#include "common.h"
}
#include <cstring>
#include <iostream>
#include <vector>
#include "SymbolTable.h"
#include "Symbol.h"
#include "Type.h"
#include "Instruction.h"
#include "Module.h"
#include "BasicBlock.h"
#include <fstream>
/*
Define classes for nonterminals, identifiers and productions, the corresponding grammar structure is commented right above each definition
*/
using namespace std;
class Instruction;
class Module;
class BasicBlock;
class ParseTree {
protected:
static SymbolTable* symbolTable;
static TupleType* EMPTY_TYPE;
static Module* module;
public:
static char* getContent(const char *nodeName);
int lineNumber;
};
class EXTDEFS;
//PROGRAM : EXTDEFS
class PROGRAM : public ParseTree {
private:
EXTDEFS* extdefs;
public:
PROGRAM(tree* rawTree);
void Typer();
void Gen();
void Emit(ofstream& os);
void Optimize();
};
class EXTDEFS : public ParseTree {
public:
static EXTDEFS* createEXTDEFS(tree* rawTree);
virtual void Typer() = 0;
virtual void Gen() = 0;
};
//EXTDEFS : EXTDEF EXTDEFS
class EXTDEF;
class EXTDEFS1 : public EXTDEFS {
private:
EXTDEF* extdef;
EXTDEFS* extdefs;
public:
EXTDEFS1(tree* rawTree);
void Typer();
void Gen();
};
//EXTDEFS :
class EXTDEFS2 : public EXTDEFS {
public:
EXTDEFS2(tree* rawTree);
void Typer();
void Gen();
};
class EXTDEF : public ParseTree {
public:
static EXTDEF* createEXTDEF(tree* rawTree);
virtual void Typer() = 0;
virtual void Gen() = 0;
};
//EXTDEF : SPEC EXTVARS SEMI
class SPEC;
class EXTVARS;
class EXTDEF1 : public EXTDEF {
private:
SPEC* spec;
EXTVARS* extvars;
public:
EXTDEF1(tree* rawTree);
void Typer();
void Gen();
};
//EXTDEF : SPEC FUNC STMTBLOCK
class FUNC;
class STMTBLOCK;
class EXTDEF2 : public EXTDEF {
private:
SPEC* spec;
FUNC* func;
STMTBLOCK* stmtblock;
public:
EXTDEF2(tree* rawTree);
void Typer();
void Gen();
};
class EXTVARS : public ParseTree {
public:
static EXTVARS* createEXTVARS(tree* rawTree);
virtual void Typer(Type* type = EMPTY_TYPE) = 0;
virtual void SetFieldSymbols(SymbolTableFrame* fieldSymbol) = 0;
virtual void Gen() = 0;
};
//EXTVARS : DEC
class DEC;
class EXTVARS1 : public EXTVARS {
private:
DEC* dec;
public:
EXTVARS1(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE);
void Gen();
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
};
//EXTVARS : DEC COMMA EXTVARS
class EXTVARS2 : public EXTVARS {
private:
DEC* dec;
EXTVARS* extvars;
public:
EXTVARS2(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE);
void Gen();
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
};
//EXTVARS :
class EXTVARS3 : public EXTVARS {
public:
EXTVARS3(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE);
void Gen();
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
};
class SPEC : public ParseTree {
friend class PARA;
friend class DEF;
friend class EXTDEF1;
friend class EXTDEF2;
protected:
Type* specType;
public:
static SPEC* createSPEC(tree* rawTree);
virtual Type* Typer() = 0;
virtual SymbolTableFrame* GetFieldSymbols() = 0;
virtual void Gen() = 0;
};
//SPEC : TYPE
class TYPE;
class SPEC1 : public SPEC {
private:
TYPE* type;
public:
SPEC1(tree* rawTree);
Type* Typer();
void Gen();
SymbolTableFrame* GetFieldSymbols();
};
//SPEC : STSPEC
class STSPEC;
class SPEC2 : public SPEC {
private:
STSPEC* stspec;
public:
SPEC2(tree* rawTree);
Type* Typer();
void Gen();
SymbolTableFrame* GetFieldSymbols();
};
class STSPEC : public ParseTree {
friend class SPEC2;
public:
static STSPEC* createSTSPEC(tree* rawTree);
virtual Type* Typer() = 0;
virtual SymbolTableFrame* GetFieldSymbols() = 0;
virtual void Gen() = 0;
};
//STSPEC : STRUCT OPTTAG LC DEFS RC
class OPTTAG;
class DEFS;
class STSPEC1 : public STSPEC {
private:
OPTTAG* opttag;
DEFS* defs;
public:
STSPEC1(tree* rawTree);
Type* Typer();
void Gen();
SymbolTableFrame* GetFieldSymbols();
};
//STSPEC : STRUCT ID
class ID;
class STSPEC2 : public STSPEC {
private:
ID* name;
public:
STSPEC2(tree* rawTree);
Type* Typer();
void Gen();
SymbolTableFrame* GetFieldSymbols();
};
class OPTTAG : public ParseTree {
public:
static OPTTAG* createOPPTAG(tree* rawTree);
static int anonId;
virtual void Typer(Type* type = EMPTY_TYPE) = 0;
virtual void SetFieldSymbols(SymbolTableFrame* fieldSymbols) = 0;
virtual SymbolTableFrame* GetFieldSymbols() = 0;
virtual void Gen() = 0;
virtual Symbol* GetSymbol() = 0;
};
//OPTTAG : ID
class STSPEC1;
class OPTTAG1 : public OPTTAG {
private:
ID* name;
public:
OPTTAG1(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE);
void Gen();
void SetFieldSymbols(SymbolTableFrame* fieldSymbols);
SymbolTableFrame* GetFieldSymbols();
Symbol* GetSymbol();
};
//OPTTAG :
class OPTTAG2 : public OPTTAG {
private:
Symbol* symbol;
public:
OPTTAG2(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE);
void Gen();
void SetFieldSymbols(SymbolTableFrame* fieldSymbols);
SymbolTableFrame* GetFieldSymbols();
Symbol* GetSymbol();
};
class VAR : public ParseTree {
public:
static VAR* createVAR(tree* rawTree, int dimension);
static void GenInits(Type* varType, Instruction* address, std::vector<Instruction*>* initValues, std::vector<BasicBlock*>* basicBlocks, int& counter);
virtual Type* Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL) = 0;
virtual void SetFieldSymbols(SymbolTableFrame* fieldSymbol) = 0;
virtual void Gen(std::vector<Instruction*>* initValues, std::vector<BasicBlock*>* basicBlocks = NULL) = 0;
virtual void Gen() = 0;
virtual string GetName() = 0;
virtual Symbol* GetSymbol() = 0;
};
//VAR : ID
class VAR1 : public VAR {
private:
ID* name;
public:
VAR1(tree* rawTree, int dimension);
Type* Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL);
void Gen(std::vector<Instruction*>* initValues, std::vector<BasicBlock*>* basicBlocks = NULL);
void Gen();
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
string GetName();
Symbol* GetSymbol();
};
//VAR : VAR LB INT RB
class NUM;
class VAR2 : public VAR {
private:
VAR* var;
NUM* num;
public:
VAR2(tree* rawTree, int dimension);
Type* Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL);
void Gen(std::vector<Instruction*>* initValues, std::vector<BasicBlock*>* basicBlocks = NULL);
void Gen();
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
string GetName();
Symbol* GetSymbol();
};
//FUNC : ID LP PARAS RP
class PARAS;
class FUNC : public ParseTree {
private:
PARAS* paras;
public:
ID* name;
FUNC(tree* rawTree);
Type* Typer(Type* type);
void Gen();
void SetFieldSymbols(SymbolTableFrame* fieldSymbols);
SymbolTableFrame* GetFieldSymbols();
Symbol* GetSymbol();
vector<Symbol*>* CollectParaSymbols();
};
class PARAS : public ParseTree {
public:
static PARAS* createPARAS(tree* rawTree);
virtual Structure* Typer() = 0;
virtual void Gen() = 0;
virtual vector<Symbol*>* CollectParaSymbols() = 0;
};
//PARAS : PARA COMMA PARAS
class PARA;
class PARAS1 : public PARAS {
private:
PARA* para;
PARAS* paras;
public:
PARAS1(tree* rawTree);
Structure* Typer();
void Gen();
vector<Symbol*>* CollectParaSymbols();
};
//PARAS : PARA
class PARAS2 : public PARAS {
private:
PARA* para;
public:
PARAS2(tree* rawTree);
Structure* Typer();
void Gen();
vector<Symbol*>* CollectParaSymbols();
};
//PARAS :
class PARAS3 : public PARAS {
public:
PARAS3(tree* rawTree);
Structure* Typer();
void Gen();
vector<Symbol*>* CollectParaSymbols();
};
//PARA : SPEC VAR
class PARA : public ParseTree {
private:
SPEC* spec;
VAR* var;
public:
PARA(tree* rawTree);
Type* Typer();
void Gen();
string GetName();
Symbol* GetSymbol();
};
//STMTBLOCK LC DEFS STMTS RC
class STMTS;
class STMTBLOCK : public ParseTree {
private:
DEFS* defs;
STMTS* stmts;
public:
STMTBLOCK(tree* rawTree);
Type* Typer();
void GenBasicBlocks(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
class STMTS : public ParseTree {
public:
static STMTS* createSTMTS(tree* rawTree);
virtual Type* Typer() = 0;
virtual void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL) = 0;
};
//STMTS : STMT STMTS
class STMT;
class STMTS1 : public STMTS {
private:
STMT* stmt;
STMTS* stmts;
public:
STMTS1(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
//STMTS :
class STMTS2 : public STMTS {
public:
STMTS2(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
class STMT : public ParseTree {
public:
static STMT* createSTMT(tree* rawTree);
virtual Type* Typer() = 0;
virtual void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL) = 0;
};
//STMT : EXP SEMI
class EXP;
class STMT1 : public STMT {
private:
EXP* exp;
public:
STMT1(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
//STMT : STMTBLOCK
class STMT2 : public STMT {
private:
STMTBLOCK* stmtblock;
public:
STMT2(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
//STMT : RETURN EXP SEMI
class STMT3 : public STMT {
private:
EXP* exp;
public:
STMT3(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
//STMT : IF LP EXP RP STMT ESTMT
class ESTMT;
class STMT4 : public STMT {
private:
EXP* exp;
STMT* stmt;
ESTMT* estmt;
public:
STMT4(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
//STMT : FOR LP FOREXP SEMI FOREXP SEMI FOREXP RP STMT
class FOREXP;
class STMT5 : public STMT {
private:
FOREXP *forexp1, *forexp2, *forexp3;
STMT* stmt;
public:
STMT5(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
//STMT : CONT SEMI
class STMT6 : public STMT {
public:
STMT6(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
//STMT : BREAK SEMI
class STMT7 : public STMT {
public:
STMT7(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
class ESTMT : public ParseTree {
public:
bool isEmpty;
static ESTMT* createESTMT(tree* rawTree);
virtual Type* Typer() = 0;
virtual void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL) = 0;
};
//ESTMT : ELSE STMT
class ESTMT1 : public ESTMT {
private:
STMT* stmt;
public:
ESTMT1(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
//ESTMT :
class ESTMT2 : public ESTMT {
public:
ESTMT2(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* next = NULL,
BasicBlock* cont = NULL,
BasicBlock* breakTo = NULL);
};
class DEFS : public ParseTree {
public:
static DEFS* createDEFS(tree* rawTree);
virtual void Typer(Type* type = EMPTY_TYPE) = 0;
virtual void Gen(std::vector<BasicBlock*>* basicBlocks = NULL) = 0;
};
//DEFS : DEF DEFS
class DEF;
class DEFS1 : public DEFS {
private:
DEF* def;
DEFS* defs;
public:
DEFS1(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE);
void Gen(std::vector<BasicBlock*>* basicBlocks = NULL);
};
//DEFS :
class DEFS2 : public DEFS {
public:
DEFS2(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE);
void Gen(std::vector<BasicBlock*>* basicBlocks = NULL);
};
//DEF : SPEC DECS SEMI
class DECS;
class DEF : public ParseTree {
private:
SPEC* spec;
DECS* decs;
public:
DEF(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE);
void Gen(std::vector<BasicBlock*>* basicBlocks = NULL);
};
class DECS : public ParseTree {
public:
static DECS* createDECS(tree* rawTree);
virtual void Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL) = 0;
virtual void SetFieldSymbols(SymbolTableFrame* fieldSymbol) = 0;
virtual void Gen(std::vector<BasicBlock*>* basicBlocks) = 0;
};
//DECS : DEC COMMA DECS
class DECS1 : public DECS {
private:
DEC* dec;
DECS* decs;
public:
DECS1(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL);
void Gen(std::vector<BasicBlock*>* basicBlocks);
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
};
//DECS : DEC
class DECS2 : public DECS {
private:
DEC* dec;
public:
DECS2(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL);
void Gen(std::vector<BasicBlock*>* basicBlocks);
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
};
class DEC : public ParseTree {
public:
static DEC* createDEC(tree* rawTree);
virtual void Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL) = 0;
virtual void SetFieldSymbols(SymbolTableFrame* fieldSymbol) = 0;
virtual void Gen(std::vector<BasicBlock*>* basicBlocks = NULL) = 0;
};
//DEC : VAR
class DEC1 : public DEC {
private:
VAR* var;
public:
DEC1(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL);
void Gen(std::vector<BasicBlock*>* basicBlocks = NULL);
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
};
//DEC : VAR ASSIGNOP INIT
class INIT;
class DEC2 : public DEC {
private:
VAR* var;
INIT* init;
public:
DEC2(tree* rawTree);
void Typer(Type* type = EMPTY_TYPE, Structure* structureType = NULL);
void Gen(std::vector<BasicBlock*>* basicBlocks = NULL);
void SetFieldSymbols(SymbolTableFrame* fieldSymbol);
};
class INIT : public ParseTree {
public:
static INIT* createINIT(tree* rawTree);
virtual Structure* Typer() = 0;
virtual vector<Instruction*>* Gen(vector<BasicBlock*>* basicBlocks = NULL) = 0;
};
//INIT : EXP
class INIT1: public INIT {
private:
EXP* exp;
public:
INIT1(tree* rawTree);
Structure* Typer();
vector<Instruction*>* Gen(vector<BasicBlock*>* basicBlocks = NULL);
};
//INIT LC ARGS RC
class ARGS;
class INIT2 : public INIT {
private:
ARGS* args;
public:
INIT2(tree* rawTree);
Structure* Typer();
vector<Instruction*>* Gen(vector<BasicBlock*>* basicBlocks = NULL);
};
class FOREXP : public ParseTree {
public:
static FOREXP* createFOREXP(tree* rawTree);
virtual Type* Typer() = 0;
virtual void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL) = 0;
};
//FOREXP : EXP
class FOREXP1 : public FOREXP {
private:
EXP* exp;
public:
FOREXP1(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
};
//FOREXP :
class FOREXP2 : public FOREXP {
public:
FOREXP2(tree* rawTree);
Type* Typer();
void Gen(std::vector<BasicBlock*>* basicBlocks,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
};
class EXP : public ParseTree {
public:
static EXP* createEXP(tree* rawTree);
virtual Type* Typer() = 0;
virtual SymbolTableFrame* GetFieldSymbols() = 0;
virtual Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL) = 0;
virtual string GetIDName() = 0;
};
//EXP : EXP BINARYOP EXP
class OP;
class EXP1 : public EXP {
private:
EXP *exp1, *exp2;
OP* op;
public:
EXP1(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP : UNARYOP EXP
class EXP2 : public EXP {
private:
OP* op;
EXP* exp;
public:
EXP2(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP : '-' EXP
class EXP3 : public EXP {
private:
EXP* exp;
public:
EXP3(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP : LP EXP RP
class EXP4 : public EXP {
private:
EXP* exp;
public:
EXP4(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP : ID LP ARGS RP
class ID;
class EXP5 : public EXP {
private:
ID* name;
ARGS* args;
public:
EXP5(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP : ID ARRS
class ARRS;
class EXP6 : public EXP {
private:
ID* name;
ARRS* arrs;
public:
EXP6(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP : EXP DOT ID
class EXP7 : public EXP {
private:
EXP* exp;
ID* name;
public:
EXP7(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP : INT
class EXP8 : public EXP {
private:
NUM* num;
public:
EXP8(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP : ID ARRS ASSIGNOP EXP
class EXP9 : public EXP {
private:
ID* name;
ARRS* arrs;
EXP* exp;
char* op;
public:
EXP9(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
//EXP DOT ID ASSIGNOP EXP
class EXP10 : public EXP {
private:
EXP* exp1;
ID* name;
EXP* exp2;
char* op;
public:
EXP10(tree* rawTree);
Type* Typer();
Instruction* Gen(std::vector<BasicBlock*>* basicBlocks, bool leftVal = false,
BasicBlock* trueList = NULL,
BasicBlock* falseList = NULL);
SymbolTableFrame* GetFieldSymbols();
string GetIDName();
};
class ARRS : public ParseTree {
public:
static ARRS* createARRS(tree* rawTree);
virtual Type* Typer(Type* type = EMPTY_TYPE) = 0;
virtual int Dimension() = 0;
virtual Instruction* Gen(Instruction* address, Type* arrayType, vector<BasicBlock*>* basicBlocks) = 0;
virtual bool isEmpty() = 0;
};
//ARRS : LB EXP RB ARRS
class ARRS1 : public ARRS {
private:
EXP* exp;
ARRS* arrs;
public:
ARRS1(tree* rawTree);
Type* Typer(Type* type = EMPTY_TYPE);
Instruction* Gen(Instruction* address, Type* arrayType, vector<BasicBlock*>* basicBlocks);
int Dimension();
bool isEmpty();
};
//ARRS :
class ARRS2 : public ARRS {
public:
ARRS2(tree* rawTree);
Type* Typer(Type* type = EMPTY_TYPE);
Instruction* Gen(Instruction* address, Type* arrayType, vector<BasicBlock*>* basicBlocks);
int Dimension();
bool isEmpty();
};
class ARGS : public ParseTree {
public:
static ARGS* createARGS(tree* rawTree);
virtual Structure* Typer() = 0;
virtual vector<Instruction*>* Gen(vector<BasicBlock*>* basicBlocks, bool leftValue = false) = 0;
};
//ARGS : EXP COMMA ARGS
class ARGS1 : public ARGS {
private:
EXP* exp;
ARGS* args;
public:
ARGS1(tree* rawTree);
Structure* Typer();
vector<Instruction*>* Gen(vector<BasicBlock*>* basicBlocks, bool leftValue = false);
};
//ARGS : EXP
class ARGS2 : public ARGS {
private:
EXP* exp;
public:
ARGS2(tree* rawTree);
Structure* Typer();
vector<Instruction*>* Gen(vector<BasicBlock*>* basicBlocks, bool leftValue = false);
};
//ARGS :
class ARGS3 : public ARGS {
public:
ARGS3(tree* rawTree);
Structure* Typer();
vector<Instruction*>* Gen(vector<BasicBlock*>* basicBlocks, bool leftValue = false);
};
class EMPTY : public ParseTree {
public:
void Type() {};
void Gen() {};
};
class ID : public ParseTree {
private:
SymbolTableFrame* fieldSymbols;
int dimension;
public:
Symbol* symbol;
ID(tree* rawTree, bool isFunction, bool isType, int dimension);
ID(tree* rawTree, int dimension);
ID(tree* rawTree, SymbolTableFrame* fieldSymbols, int dimension);
Type* Typer(Type* type = EMPTY_TYPE);
void Gen() {};
void SetFieldSymbols(SymbolTableFrame* fieldSymbols);
SymbolTableFrame* GetFieldSymbols();
};
class NUM : public ParseTree {
public:
int num;
NUM(tree* rawTree);
Type* Typer();
void Gen() {};
};
class TYPE : public ParseTree {
private:
char* type;
public:
TYPE(tree* rawTree);
Type* Typer();
void Gen() {};
};